📄 frame1.java
字号:
package statusbar;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame1 extends JFrame { JPanel contentPane; BorderLayout borderLayout1 = new BorderLayout(); Label label1 = new Label(); Button button1 = new Button(); Button button2 = new Button(); Button button3 = new Button(); Button button4 = new Button(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setResizable(false); this.setSize(new Dimension(266, 186)); this.setTitle("状态栏演示程序"); button1.setLabel("button1"); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); button2.setLabel("button2"); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); button3.setLabel("button3"); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button3_actionPerformed(e); } }); button4.setLabel("button4"); button4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button4_actionPerformed(e); } }); contentPane.add(label1, BorderLayout.SOUTH); contentPane.add(button1, BorderLayout.WEST); contentPane.add(button2, BorderLayout.CENTER); contentPane.add(button3, BorderLayout.EAST); contentPane.add(button4, BorderLayout.NORTH); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void button1_actionPerformed(ActionEvent e) {label1.setText("You hava clicked button1"); } void button2_actionPerformed(ActionEvent e) {label1.setText("You hava clicked button2"); } void button3_actionPerformed(ActionEvent e) {label1.setText("You hava clicked button3"); } void button4_actionPerformed(ActionEvent e) {label1.setText("You hava clicked button4"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -