189 8069 5689

guijava代码 guid java

JAVA中GUI登录界面设计源代码是什么?

import java.awt.BorderLayout;

成都创新互联公司是一家专注于网站设计、成都网站制作与策划设计,伍家岗网站建设哪家好?成都创新互联公司做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:伍家岗等地区。伍家岗做网站价格咨询:18982081108

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();

}

}

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.*;

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();

}

}

效果图


文章标题:guijava代码 guid java
网页链接:http://cdxtjz.cn/article/hioopc.html

其他资讯