import javax.swing.*;\x0d\x0aimport java.awt.*;\x0d\x0aimport java.awt.event.*;\x0d\x0apublic class Test3 extends JFrame implements ActionListener{\x0d\x0a JMenu m;\x0d\x0a JMenuItem mi1,mi2;\x0d\x0a JMenuBar mb;\x0d\x0a \x0d\x0a public Test3(){\x0d\x0a m = new JMenu("學(xué)生查詢");\x0d\x0a mi1 = new JMenuItem("確認(rèn)");\x0d\x0a mi2 = new JMenuItem("取消");\x0d\x0a mb = new JMenuBar();\x0d\x0a m.add(mi1);\x0d\x0a m.add(mi2);\x0d\x0a mb.add(m);\x0d\x0a this.setJMenuBar(mb);\x0d\x0a this.setSize(400,300);\x0d\x0a this.setLocationRelativeTo(null);//窗口居中\(zhòng)x0d\x0a this.setVisible(true);\x0d\x0a this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\x0d\x0a mi1.addActionListener(this);\x0d\x0a mi2.addActionListener(this);\x0d\x0a }\x0d\x0a public static void main(String[] args){\x0d\x0a new Test3();\x0d\x0a \x0d\x0a }\x0d\x0a public void actionPerformed(ActionEvent ae){\x0d\x0a if(ae.getSource()==mi1){\x0d\x0a JOptionPane.showMessageDialog(null, "你點(diǎn)擊了確定按鈕"); }else{\x0d\x0a JOptionPane.showMessageDialog(null, "你點(diǎn)擊了取消按鈕"); }\x0d\x0a }\x0d\x0a \x0d\x0a}

發(fā)展壯大離不開廣大客戶長期以來的信賴與支持,我們將始終秉承“誠信為本、服務(wù)至上”的服務(wù)理念,堅(jiān)持“二合一”的優(yōu)良服務(wù)模式,真誠服務(wù)每家企業(yè),認(rèn)真做好每個細(xì)節(jié),不斷完善自我,成就企業(yè),實(shí)現(xiàn)共贏。行業(yè)涉及成都隧道混凝土攪拌車等,在成都網(wǎng)站建設(shè)公司、全網(wǎng)營銷推廣、WAP手機(jī)網(wǎng)站、VI設(shè)計(jì)、軟件開發(fā)等項(xiàng)目上具有豐富的設(shè)計(jì)經(jīng)驗(yàn)。
java做窗口的話,需要用swing技術(shù),之后創(chuàng)建JFrame 等組件,即可完成窗口創(chuàng)建工作。
package inter.frame;import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;public class MenuTest { /**
* @param args
*/
JFrame frame; //定義一個窗口架構(gòu)
JMenuBar mb;//定義窗口的菜單工具欄
JMenu m; //定義菜單
JMenuItem mi1;//定義菜單的內(nèi)容
JMenuItem mi2; //定義菜單的內(nèi)容
public MenuTest() {
initFrame();
initAction();
}
public void initFrame() {
frame = new JFrame();
mb = new JMenuBar();
m = new JMenu("學(xué)生查詢");
mi1 = new JMenuItem("確認(rèn)");
mi2 = new JMenuItem("取消"); m.add(mi1);
m.add(mi2);
mb.add(m);
frame.add(mb, BorderLayout.NORTH);
frame.setSize(300, 300); //設(shè)置窗口大小
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置退出時關(guān)閉窗口
frame.setVisible(true);//設(shè)置窗口可見
} public void initAction() {
mi1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 具體實(shí)現(xiàn)代碼根據(jù)實(shí)際要求填寫
System.out.println("click");
JOptionPane.showMessageDialog(null, "你點(diǎn)擊了確定按鈕");
}
});
mi2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 具體實(shí)現(xiàn)代碼根據(jù)實(shí)際要求填寫
JOptionPane.showMessageDialog(null, "你點(diǎn)擊了取消按鈕");
}
});
} public static void main(String[] args) {
new MenuTest();//執(zhí)行菜單創(chuàng)建
}}
圖片看起來很模糊,隱約看到需要一個登錄窗口,那就分享一下以前練習(xí)的登錄窗口demo吧。
先上效果圖:
登錄界面
源碼如下:
AbsoluteLoginFrame.java
public class AbsoluteLoginFrame extends JFrame {
private static final int LOGIN_WIDTH = 600;
private static final int LOGIN_HEIGHT = 400;
private static final long serialVersionUID = -2381351968820980500L;
public AbsoluteLoginFrame(){
? //設(shè)置窗口標(biāo)題
? setTitle("登錄界面");
? //設(shè)置一個初始面板,填充整個窗口
? JPanel loginPanel = new JPanel();
? //設(shè)置背景顏色
? loginPanel.setBackground(new Color(204, 204, 204));//#CCC
? loginPanel.setLayout(null);
? JPanel centerPanel = new JPanel();
? centerPanel.setBackground(Color.WHITE);
? centerPanel.setBounds(114, 70, 360, 224);
? centerPanel.setLayout(null);
? JLabel jLabel = new JLabel("用戶名:");
? jLabel.setOpaque(true);
? jLabel.setBackground(Color.YELLOW);
? jLabel.setBounds(60, 60, 54, 20);
? JLabel label = new JLabel("密? ? 碼:");
? label.setOpaque(true);
? label.setBackground(Color.CYAN);
? label.setBounds(60, 90, 54, 20);
? JTextField textField = new JTextField(15);
? textField.setBounds(130, 60, 166, 21);
? JPasswordField passwordField = new JPasswordField(15);
? passwordField.setBounds(130, 90, 166, 21);
? JButton jButton = new JButton("登錄");
? jButton.setBounds(148, 120, 62, 28);
? centerPanel.add(jLabel);
? centerPanel.add(label);
? centerPanel.add(textField);
? centerPanel.add(jButton);
? centerPanel.add(passwordField);
? loginPanel.add(centerPanel);
? getContentPane().add(loginPanel);//將初始面板添加到窗口中
? setSize(LOGIN_WIDTH, LOGIN_HEIGHT);//設(shè)置窗口大小
? setLocation(Screen.getCenterPosition(LOGIN_WIDTH, LOGIN_HEIGHT));//設(shè)置窗口位置
? setDefaultCloseOperation(EXIT_ON_CLOSE);//設(shè)置窗口默認(rèn)關(guān)閉方式
? setResizable(false);
? setVisible(true);
}
public static void main(String[] args) {
? new AbsoluteLoginFrame();
}
}
Screen.java
public class Screen {
private int width;
private int height;
public Screen(){
? Toolkit toolkit = Toolkit.getDefaultToolkit();
? Dimension screenSize = toolkit.getScreenSize();
? this.width = screenSize.width;
? this.height = screenSize.height;
}
public static Point getCenterPosition(int width, int height){
? Screen screen = new Screen();
? int x = (screen.getWidth() - width) / 2;
? int y = (screen.getHeight() - height) / 2;
? return new Point(x, y);
}
public int getWidth() {
? return width;
}
public void setWidth(int width) {
? this.width = width;
}
public int getHeight() {
? return height;
}
public void setHeight(int height) {
? this.height = height;
}
}
新聞名稱:java代碼實(shí)現(xiàn)窗口,java編寫窗口
新聞來源:http://chinadenli.net/article26/hchdjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站導(dǎo)航、移動網(wǎng)站建設(shè)、Google、自適應(yīng)網(wǎng)站、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)