导航:首页 > 编程语言 > java图形界面gui设计

java图形界面gui设计

发布时间:2021-03-04 02:07:44

1. java图形界面(GUI)

import java.awt.*;
import java.awt.event.*;
import java.util.Random;

public class Window extends Frame{
Button button1 = new Button("开始");
Button button2 = new Button("结束");
TextField textfield = new TextField();
static Random random = new Random();
String string = null;
boolean bstart = false;
Thread thread;

public void launchFrame() {
.setLocation(500, 200);
this.setLayout(new BorderLayout());
this.add(button1, new BorderLayout().WEST);
this.add(button2, new BorderLayout().EAST);
this.add(textfield, new BorderLayout().NORTH);
button1.addActionListener(new Button1Listener());
button2.addActionListener(new Button2Listener());
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
pack();
setVisible(true);

}

private class Button1Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
bstart = true;
thread = new Thread(new NumProce());
thread.start();
}
}

private class Button2Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
bstart = false;
}
}

private class NumProce implements Runnable {

private void numproce() {
string = Integer.toString(random.nextInt()); /*nextint的括号中处可以修改产生随机数的范围*/
textfield.setText(string);
}

public void run() {
while(bstart) {
try {
numproce();
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

public static void main(String[] args) {
new Window().launchFrame();
}
}

2. java界面设计的GUI是什么东西

如果要写桌面基于Swing窗体的程序,建议用netbeans.
NB的Swing插件比eclipse好用很多。也可以在NB里面画好了窗体复制到eclipse里去用。

3. 怎样用JAVA的GUI(图形用户界面)来设计一个计算机呢

你只能做一个计算器而不是一个计算机,计算机跟计算器是两种不同的东西,特别是对于计算机专业而言,具体的网络一下JAVA计算器,肯定大把

4. 用Java设计一个图形界面(GUI)的计算器应用程序,完成简单的算术运算

下午发
五分钟搞定,先给你发个简单的,照例子自己去做你想要的计算器
package aaa;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class YunSuan implements ActionListener,ItemListener
{
public static JFrame jf;
public static Container c;
public static JTextField jtf1,jtf2,jtf3;
public static JButton jb1;
public static Choice c2;

public static String fuhao="";

public YunSuan()
{
jf=new JFrame("加减乘除运算");
c=jf.getContentPane();
c.setLayout(new FlowLayout());
jtf1=new JTextField(10);
jtf2=new JTextField(10);
jtf3=new JTextField(10);
c2=new Choice();
jb1=new JButton("=");

}

public void Jiemian()
{

c.add(jtf1);
c2.addItemListener(this);
c2.add("");
c2.add("+");
c2.add("-");
c2.add("*");
c2.add("/");
c.add(c2);
c.add(jtf2);
jb1.addActionListener(this);
c.add(jb1);
c.add(jtf3);

jf.setLocation(200,100);
jf.setVisible(true);
jf.pack();
}
public static void main(String args[])
{
YunSuan ys=new YunSuan();
ys.Jiemian();
}

public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double s1=Integer.parseInt(jtf1.getText());
double s2=Integer.parseInt(jtf2.getText());
double result=0;
if(fuhao.equals("+"))
{
result=s1+s2;
String result2=String.valueOf(result);
jtf3.setText(result2);
}
if(fuhao.equals("-"))
{
result=s1-s2;
String result2=String.valueOf(result);
jtf3.setText(result2);
}
if(fuhao.equals("*"))
{
result=s1*s2;
String result2=String.valueOf(result);
jtf3.setText(result2);
}
if(fuhao.equals("/"))
{
result=s1/s2;
String result2=String.valueOf(result);
jtf3.setText(result2);
}
}

public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==c2)
{
String str1=c2.getSelectedItem();
fanhui(str1);
}
}
public String fanhui(String str2)
{
return fuhao=str2;
}
}

5. 怎样用JAVA的GUI(图形用户界面)来设计一个程序!求程序和详解。

//正好以前注释过一个
importjava.awt.*;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.KeyAdapter;
importjava.awt.event.KeyEvent;
importjava.awt.image.MemoryImageSource;
importjava.util.Random;
importjavax.swing.JDialog;
importjavax.swing.JPanel;
importjavax.swing.Timer;
{
=1L;
privateRandomrandom=newRandom();
privateDimensionscreenSize;
privateJPanelgraphicsPanel;
privatefinalstaticintgap=20;
privateint[]posArr;
privateintlines;
privateintcolumns;
publicstaticvoidmain(String[]args){
newCharacterRain();
}
publicCharacterRain(){
initComponents();
}
privatevoidinitComponents(){
setLayout(newBorderLayout());
graphicsPanel=newGraphicsPanel();
add(graphicsPanel,BorderLayout.CENTER);
ToolkitdefaultToolkit=Toolkit.getDefaultToolkit();
Imageimage=defaultToolkit.createImage(newMemoryImageSource(0,0,
null,0,0));
CursorinvisibleCursor=defaultToolkit.createCustomCursor(image,
newPoint(0,0),"cursor");
setCursor(invisibleCursor);
=newKeyPressListener();
this.addKeyListener(keyPressListener);
this.setAlwaysOnTop(true);
this.setUndecorated(true);
this.getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setVisible(true);
screenSize=Toolkit.getDefaultToolkit().getScreenSize();
lines=screenSize.height/gap;//用gap来分行
columns=screenSize.width/gap;//用gap来分列
posArr=newint[columns+1];
random=newRandom();
for(inti=0;i<posArr.length;i++){
posArr[i]=random.nextInt(lines);//随机行数
}
newTimer(100,this).start();
}
privatechargetChr(){
return(char)(random.nextInt(94)+33);//返回随机字符
}
publicvoidactionPerformed(ActionEvente){
graphicsPanel.repaint();//Timer事件,graphicsPanel重绘
}
@SuppressWarnings("serial")
{
publicvoidpaint(Graphicsg){
Graphics2Dg2d=(Graphics2D)g;
g2d.setFont(getFont().deriveFont(Font.BOLD));
g2d.setColor(Color.BLACK);
g2d.fillRect(0,0,screenSize.width,screenSize.height);//设置背景色为黑色
intcurrentColumn=0;
for(intx=0;x<screenSize.width;x+=gap){
intendPos=posArr[currentColumn];//获得开始行位置
g2d.setColor(Color.GREEN);
g2d.drawString(String.valueOf(getChr()),x,endPos*gap);//画出随机开始行的字符
intcg=0;//初始黑色
intlength=25;//字符列的长度
for(intj=endPos-length;j<endPos;j++){//随机行逐列向上length行,为循环开始行
cg+=255/(length+1);//渐变色递增,0,255,0为green
if(cg>255){
cg=255;
}
g2d.setColor(newColor(0,cg,0));
g2d.drawString(String.valueOf(getChr()),x,j*gap);//画出随机行后的15行字符,颜色从黑色渐变成绿色,逐行增加
}
posArr[currentColumn]+=random.nextInt(5);//下落距离最快为4,会产生加速下落的感觉
if((posArr[currentColumn]-5)*gap>getHeight()){//如果行数位置大于屏幕高度,从新获取合适的行
posArr[currentColumn]=random.nextInt(lines);
}
currentColumn++;//下一列获取随机行
}
}
}
{
publicvoidkeyPressed(KeyEvente){
if(e.getKeyCode()==KeyEvent.VK_ESCAPE){//监听键盘事件,按ESC按键退出
System.exit(0);
}
}
}
}

6. 救急!怎样用JAVA的GUI(图形用户界面)来设计一个小程序!求程序和详解。

给你找了一个,我试过,可以用
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.*;//GUi之前要吧这两个都引进来
public class Computer extends JFrame implements ActionListener
{
JButton a1,a2,a3,a4,a5,a6,a7,a8,a9,a0;
JButton b1,b2,b3,b4;
JButton c1,c2,c3,c4;
JTextField t1,t2;
JPanel p1,p2;
JLabel bq1,bq2;
String fuhao;
Double count,count2;
boolean chose=false,cliks;

public static void main(String[] args){
Computer l = new Computer();
}
public Computer(){
Font font = new Font("宋体", Font.BOLD, 36);
Font font2 = new Font("宋体", Font.BOLD, 20);

a1 = new JButton("1");
a1.setFont(font);
a1.addActionListener(this);
a2 = new JButton("2");
a2.setFont(font);
a2.addActionListener(this);
a3 = new JButton("3");
a3.setFont(font);
a3.addActionListener(this);
a4 = new JButton("4");
a4.setFont(font);
a4.addActionListener(this);
a5 = new JButton("5");
a5.setFont(font);
a5.addActionListener(this);
a6 = new JButton("6");
a6.setFont(font);
a6.addActionListener(this);
a7 = new JButton("7");
a7.setFont(font);
a7.addActionListener(this);
a8 = new JButton("8");
a8.setFont(font);
a8.addActionListener(this);
a9 = new JButton("9");
a9.setFont(font);
a9.addActionListener(this);
a0 = new JButton("0");
a0.setFont(font);
a0.addActionListener(this);

b1 = new JButton("清空");
b1.addActionListener(this);
b2 = new JButton("返回");
b2.addActionListener(this);
b3 = new JButton(".");
b3.addActionListener(this);

b4 = new JButton("=");
b4.addActionListener(this);

c1 = new JButton("+");
c1.addActionListener(this);

c2 = new JButton("-");
c2.addActionListener(this);
c3 = new JButton("x");
c3.addActionListener(this);
c4 = new JButton("÷");
c4.addActionListener(this);

t1 = new JTextField(25);
t2 = new JTextField(35);
t1.setFont(font2);
t2.setFont(font2);

p1 = new JPanel();
p2 = new JPanel();

bq1 = new JLabel("结");
bq2 = new JLabel("果");

p1.setLayout(new GridLayout(2,3));
p2.setLayout(new GridLayout(4,4));

p1.add(t1);p1.add(b1);p1.add(b2);
p1.add(t2);p1.add(bq1);p1.add(bq2 );

p2.add(a1);p2.add(a2);p2.add(a3);p2.add(c1);
p2.add(a4);p2.add(a5);p2.add(a6);p2.add(c2);
p2.add(a7);p2.add(a8);p2.add(a9);p2.add(c3);
p2.add(b3);p2.add(a0);p2.add(b4);p2.add(c4);

this.add(p1,BorderLayout.NORTH);
this.add(p2,BorderLayout.CENTER);

this.setSize(460,380);
this.setTitle("简易计算器");
this.setLocation(200,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object temp = e.getSource();
if(temp == a1){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"1");
chose=false;
}
if(temp == a2){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"2");
chose=false;

}
if(temp == a3){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"3");
chose=false;

}
if(temp == a4){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"4");
chose=false;
}
if(temp == a5){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"5");
chose=false;
}
if(temp == a6){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"6");
chose=false;
}
if(temp == a7){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"7");
chose=false;
}
if(temp == a8){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"8");
chose=false;
}
if(temp == a9){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"9");
chose=false;
}
if(temp == a0){
if(chose==true){t1.setText("");t2.setText("");}
t1.setText(t1.getText()+""+"0");
chose=false;
}
if(temp==b3){
cliks=true;
for(int i=0;i<t1.getText().length();i++){
if('.'==t1.getText().charAt(i)){
cliks=false;
break;
}
if(cliks==true){
t1.setText(t1.getText()+".");
}
}
}

if(temp== c1){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "+";
}
if(temp== c2){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "-";
}
if(temp== c3){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "*";
}

if(temp== c4){
count=Double.parseDouble(t1.getText());
t1.setText("");
fuhao = "÷";
}
if(temp==b1){
t1.setText("");
t2.setText("");
}
if(temp==b2){
String s=t1.getText();
t1.setText("");
for(int i=0;i<s.length()-1;i++){
char a = s.charAt(i);
t1.setText(t1.getText()+a);
}
}
if(temp== b4){
count2=Double.parseDouble(t1.getText());
t1.setText("");
if(fuhao=="+"){
//int sum=count+count2;
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count+count2+"");
chose=true;
}
if(fuhao=="-"){
//int sum=count+count2;
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count-count2+"");
chose=true;
}
if(fuhao=="*"){
//int sum=count+count2;
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count*count2+"");
chose=true;
}
if(fuhao=="÷"){
//int sum=count+count2;
if(count2==0){
t1.setText(count+""+fuhao+""+count2+"");
t2.setText("除数不能为0");
return;
}
t1.setText(count+""+fuhao+""+count2+""+"=");
t2.setText(count/count2+"");
chose=true;
}

}
}
}

7. 使用Java的GUI图形用户界面编程设计并编写一个计算器程序

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Calculator extends JFrame {
JButton b0 = new JButton("0");
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
JButton b6 = new JButton("6");
JButton b7 = new JButton("7");
JButton b8 = new JButton("8");
JButton b9 = new JButton("9");
JButton jiaButton = new JButton("+");
JButton jianButton = new JButton("-");
JButton chengButton = new JButton("*");
JButton chuButton = new JButton("/");
JButton yuButton = new JButton("%");
JButton jjButton = new JButton("+/-");
JButton sqrtButton = new JButton("sqrt");
JButton dianButton = new JButton(".");
JButton dengButton = new JButton("=");
JButton Button = new JButton("1/x");
JButton backButton = new JButton("Backpace");
JButton cButton = new JButton("C");
public double op1;
public double op2;
public static final int JIA = 0;
public static final int JIAN = 1;
public static final int CHENG = 2;
public static final int CHU = 3;
public static final int JJ = 4;
public static final int DIAN = 5;
public int current0p = 0;
private boolean opEnd = false;

JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JTextField result = new JTextField(20);

public Calculator() {
initPanel2();
initPanel3();
panel2.setLayout(new GridLayout(5, 4));
panel1.setLayout(new BorderLayout());
panel1.add(panel3, BorderLayout.NORTH);// 设置位置
panel1.add(panel2, BorderLayout.CENTER);// 设置位置
getContentPane().add(panel1);
addActionListeners();
setSize(260, 260);
setLocation(500, 300);
setVisible(true);
setDefaultCloseOperation(Calculator.EXIT_ON_CLOSE);
this.setResizable(false);
this.setTitle("计算器");
}
private void initPanel2() {
// 把组件添加相应panel上

panel2.add(b7);
panel2.add(b8);
panel2.add(b9);
panel2.add(chuButton);

panel2.add(b4);
panel2.add(b5);
panel2.add(b6);
panel2.add(chengButton);

panel2.add(b1);
panel2.add(b2);
panel2.add(b3);
panel2.add(jianButton);

panel2.add(b0);
panel2.add(jjButton);
panel2.add(dianButton);
panel2.add(jiaButton);

panel2.add(Button);
panel2.add(yuButton);
panel2.add(sqrtButton);
panel2.add(dengButton);

}

private void addActionListeners() {
ActionHandler c = new ActionHandler();
b0.addActionListener(c);
b1.addActionListener(c);
b2.addActionListener(c);
b3.addActionListener(c);
b4.addActionListener(c);
b5.addActionListener(c);
b6.addActionListener(c);
b7.addActionListener(c);
b8.addActionListener(c);
b9.addActionListener(c);

jiaButton.addActionListener(c);
dengButton.addActionListener(c);
chengButton.addActionListener(c);
chuButton.addActionListener(c);
jianButton.addActionListener(c);
jjButton.addActionListener(c);
dianButton.addActionListener(c);
sqrtButton.addActionListener(c);
yuButton.addActionListener(c);
Button.addActionListener(c);
backButton.addActionListener(c);
cButton.addActionListener(c);
}

class ActionHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {

if (e.getSource() == b0) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "0");

}
if (e.getSource() == b1) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "1");
opEnd = true;
}

if (e.getSource() == b2) {

if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "2");
opEnd = true;
}
if (e.getSource() == b3) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "3");
opEnd = true;

}
if (e.getSource() == b4) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "4");
opEnd = true;
}
if (e.getSource() == b5) {

if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "5");
opEnd = true;
}
if (e.getSource() == b6) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "6");
opEnd = true;
}
if (e.getSource() == b7) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "7");
opEnd = true;
}
if (e.getSource() == b8) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "8");
opEnd = true;
}
if (e.getSource() == b9) {
if (opEnd == false) {
result.setText("");

}
result.setText(result.getText() + "9");
opEnd = true;
}
try {
if (e.getSource() == jiaButton) {
op1 = Double.parseDouble(result.getText());

// 2、说明操作数已经输入完毕
opEnd = false;

current0p = JIA;
}
if (e.getSource() == chengButton) {
op1 = Double.parseDouble(result.getText());

// 2、说明操作数已经输入完毕
opEnd = false;

current0p = CHENG;

}
if (e.getSource() == chuButton) {
op1 = Double.parseDouble(result.getText());

// 2、说明操作数已经输入完毕
opEnd = false;

current0p = CHU;

}
if (e.getSource() == jianButton) {
op1 = Double.parseDouble(result.getText());

// 2、说明操作数已经输入完毕
opEnd = false;

current0p = JIAN;

}

if (e.getSource() == jjButton) {
String tmp = result.getText();
if (tmp.equals("") || tmp.equals("0")) {
return;
}
if (tmp.charAt(0) == '-') {
tmp = tmp.substring(1);

} else {
tmp = '-' + tmp;
}
result.setText(tmp);
}
if (e.getSource() == dianButton) {
String tmp = result.getText();
if (tmp.equals("")) {
return;
}
if (tmp.indexOf(".") != -1) {
return;
}
tmp = tmp + ".";
result.setText(tmp);

}
if (e.getSource() == sqrtButton) {
String tmp = result.getText();
if (tmp.equals(" ")) {
return;
}
double d;
d = Double.parseDouble(tmp);// 先定义double类型d
if (d < 0) {
result.setText("不能对负数求平方根");
return;
}
op2 = Math.sqrt(d);
result.setText(op2 + "");
}

if (e.getSource() == backButton) {
String s = result.getText();
result.setText("");
for (int i = 0; i < s.length() - 1; i++) {
char a = s.charAt(i);
result.setText(result.getText() + a);
}

}
if (e.getSource() == cButton) {
result.setText("0");
opEnd = false;
}
if (e.getSource() == dengButton) {
op2 = Double.parseDouble(result.getText());

switch (current0p) {
case JIA:
result.setText(op1 + op2 + "");
break;
case JIAN:
result.setText(op1 - op2 + "");
break;
case CHENG:
result.setText(op1 * op2 + "");
break;
case CHU:
if (op2 == 0) {
result.setText("被除数不能为零");
break;
}
result.setText(op1 / op2 + "");
break;
}
opEnd = false;
}
} catch (Exception e1) {
result.setText("Wrong");
opEnd = false;
}
}

}

private void initPanel3() {

panel3.setLayout(new GridLayout(2, 1));
panel3.add(result);
panel3.add(panel4);
panel4.setLayout(new GridLayout(1, 2));

panel4.add(backButton);
panel4.add(cButton);
// panel3.setPreferredSize(new Dimension(260,65));
}

public static void main(String[] args) {
Calculator c = new Calculator();// 生成类实例

}

}

8. java做图形界面程序,GUI写出来怎么那么丑啊,java做界面...

java做图形界面程序,GUI写出来怎么那么丑啊,java做界面...
请在珍惜的时候,好好去爱

阅读全文

与java图形界面gui设计相关的资料

热点内容
国内最大的视频网站是什么 浏览:756
安徽联通刷钻代码 浏览:952
离我最近的电影院在哪 浏览:627
123.eecom 浏览:506
一部国外电影一个老头爱上一个老太 浏览:704
中云文化大数据秦龙 浏览:444
俄罗斯电影《沙漠》2021 浏览:656
中兴u930升级包 浏览:159
剧情介绍有哪些APP 浏览:528
搞笑的恋爱电影在线观看 浏览:804
十大封禁爱情电影美国 浏览:90
gl小说百度网盘txt下载 浏览:925
格瑞斯甲亢看哪些数据 浏览:587
Rocco e le storie tese (1997) 浏览:147
大数据政策措施 浏览:63
我们先在碰头电影院前面用英语怎么说 浏览:497
现代忠犬受卑微主仆 浏览:347
win10拖动文件崩溃 浏览:692
win8系统网络设置 浏览:691
眼角膜电影在线观看 浏览:317

友情链接