import java.awt.Color; import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; class Frame8 extends JFrame{ private JPanel contentPane1,contentPane2; Frame8(){ contentPane1 = new JPanel(); add(contentPane1); contentPane1.setBounds(10, 20, 100, 120); contentPane1.setBorder(BorderFactory.createLineBorder(Color.black)); contentPane1.setLayout(new FlowLayout(FlowLayout.LEFT)); JButton btn1 = new JButton("按鈕1"); btn1.setBounds(0, 0, 100, 30); contentPane1.add(btn1); contentPane2 = new JPanel(); add(contentPane2); contentPane2.setBounds(150, 20, 100, 120); contentPane2.setBorder(BorderFactory.createLineBorder(Color.black)); contentPane2.setLayout(new FlowLayout(FlowLayout.LEFT)); JButton btn2 = new JButton("按鈕2"); btn2.setBounds(100, 0, 100, 30); contentPane2.add(btn2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(null); setBounds(0,0,450,300); setTitle("Swing JFrame 視窗"); setVisible(true); } } public class FrameJPanel2 { public static void main(String[] args) { Frame8 frame = new Frame8(); } }執行結果
2014年4月16日 星期三
Swing:元件:JPanel
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言