close
參考答案:
import java.awt.event.*; import javax.swing.*; import java.awt.*; class JDD01 { public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MyJFrame().setVisible(true); } }); } } class MyJFrame extends javax.swing.JFrame { private JButton btn1, btn2, btn3, btn4, btn5; private LayoutManager layout; public MyJFrame() { this.setSize(500,400); this.setLocationRelativeTo(null); this.setLayout(new BorderLayout()); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JButton btn1 = new JButton("Button 1"); JButton btn2 = new JButton("Button 2"); JButton btn3 = new JButton("Button 3"); JButton btn4 = new JButton("Button 4"); JButton btn5 = new JButton("Button 5"); this.getContentPane().add(btn1, BorderLayout.CENTER); this.getContentPane().add(btn2, BorderLayout.EAST); this.getContentPane().add(btn3, BorderLayout.SOUTH); this.getContentPane().add(btn4, BorderLayout.WEST); this.getContentPane().add(btn5, BorderLayout.NORTH); } }
執行結果:
全站熱搜
留言列表