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();
}
}
因為你在主線程中調用了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();
}
}
效果圖
文章題目:guijava代碼 guid java
當前地址:http://vcdvsql.cn/article32/hioopc.html
成都網站建設公司_創新互聯,為您提供網站營銷、全網營銷推廣、面包屑導航、網站設計公司、云服務器、動態網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯