大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import java.awt.BorderLayout;
10年积累的成都网站设计、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站设计后付款的网站建设流程,更有岷县免费网站建设让你可以放心的选择与我们合作。
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();
}
}
因为你在主线程中调用了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();//启动
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();
}
}
效果图