javagui代码 java程序代码

JAVA GUI代码问题import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class aa implements ActionListener {
JButton jb;
public aa(JButton jb) {//构造器,把JButton传递进来,
this.jb = jb;
}
public void actionPerformed(ActionEvent e) {
jb.setVisible(false);//设置jbutton不可见
}
}
public class J1 extends JFrame{
JButton j1 = new JButton("Game1");
JButton j2 = new JButton("Game2");
J1(){
setTitle("Game");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(j1);
c.add(j2);
j1.addActionListener(new aa(j1));//把j1这个按钮传递进过去
j2.addActionListener(new aa(j2));//把j2这个按钮传递进过去
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
new J1();
}
}
效果图
帮我看看这段Java GUI代码javagui代码你好,在构造方法FrameOut()中调用setLayout()方法加入一种控件布局形式,例如加入setLayout(new FlowLayout());即可以流布局的形式显示控件 。
完整代码如下javagui代码:
import java.awt.*;
import java.awt.event.*;
public class ApplicationInOut{
public static void main(String args[ ]){
new FrameInOut();
}
}
class FrameInOut extends Frame implements ActionListener{
Label prompt;
TextField input,output;
FrameInOut( ){
super("图形界面的Java Application程序");
prompt=new Label("Java 是面向对象的语言吗?");
input=new TextField(6);
output=new TextField(20);
add(prompt);
add(input);
add(output);
input.addActionListener(this);
setLayout(new FlowLayout());//此处即为添加布局形式
setSize(800,600);
setVisible(true);//show( );
}
public void actionPerformed(ActionEvente){
output.setText(input.getText() "OK!");
}
}
JAVA GUI 代码问题因为你在主线程中调用了Threed.sleep(1000) 那么主线程就一直在这里暂停.没机会显示数字.
然后当主线程恢复的时候, 如果你设置shuzi.setVisible(true);那么就直接消失了
修改参考,
Thread t = new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(1000);
shuzi.setVisible(false);//设置不可见
} catch (Exception e1) {
return;
}
}
});
t.start();//启动
编写一个Java GUI试一下下面的代码
(如果点击按钮后没有任何变化,将窗口最小化一下就有了)
没有出现这个问题的话,也请告诉我一下~
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class painting extends JFrame implements ActionListener{
private JButton round,rectangle,ellipse,beeline;
private JLabel xaxis,yaxis,remain,information;
private JTextField xTF,yTF;
private BorderLayout layout;
private Container cp;
private JPanel pCenter;
VectorObject v=new VectorObject();//定义一个集合类用于存储按钮对象
public painting(){//构造方法------------------框架初始化-------------------
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("painting");
setSize(400,500);
layout = new BorderLayout();
cp = getContentPane();
cp.setLayout(layout);
round= new JButton("画圆");
rectangle= new JButton("画矩形");
ellipse= new JButton("画椭圆");
beeline= new JButton("画直线");
xaxis=new JLabel("x坐标");
yaxis=new JLabel("y坐标");
remain=new JLabel("右下角坐标(400,500)");
xTF=new JTextField("0",5);
yTF=new JTextField("0",5);
JPanel pUp= new JPanel();//第一个面板 在上部
pUp.add(remain);
pUp.add(xaxis);//置两个文本框
pUp.add(xTF);
pUp.add(yaxis);
pUp.add(yTF);
cp.add(pUp, "North");
//pCenter=new JPanel();//第二个面板 在中部
//pCenter.add(information);//置显示说明与画图区
//cp.add(pCenter,"Center");
JPanel pDown= new JPanel();//第三个面板 在下部
pDown.add(round);// 置四个按钮
pDown.add(rectangle);
pDown.add(ellipse);
pDown.add(beeline);
cp.add(pDown, "South");
round.addActionListener(this); //置按钮监听--------------按钮行为监听与响应-------------
rectangle.addActionListener(this);
ellipse.addActionListener(this);
beeline.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {//监听响应
v.add(e.getSource());//将按钮情况存入v中
}
public void paint(Graphics g) {//--------------绘图响应-------------
super.paint(g);
int xx=Integer.parseInt(xTF.getText());//获取位置值
int yy=Integer.parseInt(yTF.getText());
int size=0;
Object o;
//while(v.size()!=size){//当用户点击按钮选择某一种图形时,v的大小就会比size值大1 , 当绘图完成后,v.size又等于size;效果就是:出现点击 即刻处理
o=v.lastElement();
if(o == round) {g.drawOval(xx,yy,50,50);}
else if (o == rectangle){g.drawRect(xx,yy,100,50);}
else if (o == ellipse) {g.drawOval(xx,yy,100,50);}
else if(o == beeline) {g.drawLine(xx,yy,xx 100,yy);}
size;
【javagui代码 java程序代码】}
}
public static void main(String[] args){// ------------程序入口-------------
JFrame frame = new painting();
frame.setVisible(true);
}
}
JAVA中GUI登录界面设计源代码是什么?import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Login {
private JFrame frame = new JFrame("登录");
private Container c = frame.getContentPane();
private JTextField username = new JTextField();
private JPasswordField password = new JPasswordField();
private JButton ok = new JButton("确定");
private JButton cancel = new JButton("取消");
public Login(){
frame.setSize(300,200);
c.setLayout(new BorderLayout());
initFrame();
frame.setVisible(true);
}
private void initFrame() {
//顶部
JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout());
titlePanel.add(new JLabel("系统管理员登录"));
c.add(titlePanel,"North");
//中部表单
JPanel fieldPanel = new JPanel();
fieldPanel.setLayout(null);
JLabel l1 = new JLabel("用户名:");
l1.setBounds(50, 20, 50, 20);
JLabel l2 = new JLabel("密码:");
l2.setBounds(50, 60, 50, 20);
fieldPanel.add(l1);
fieldPanel.add(l2);
username.setBounds(110,20,120,20);
password.setBounds(110,60,120,20);
fieldPanel.add(username);
fieldPanel.add(password);
c.add(fieldPanel,"Center");
//底部按钮
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
buttonPanel.add(ok);
buttonPanel.add(cancel);
c.add(buttonPanel,"South");
}
public static void main(String[] args){
new Login();
}
}
关于javagui代码和java程序代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读