jframe是最低层的容器,相当于构建一个windows窗口
jpanel是窗口中的容器,用来容纳各种其他的组件
并可以使用很多工具来增强表现力
如:layout,doublebuffer等

解决方案 »

  1.   

    jframe是最低层的容器,相当于构建一个windows窗口
    jpanel是窗口中的容器,用来容纳各种其他的组件
    并可以使用很多工具来增强表现力
    如:layout,doublebuffer等
      

  2.   

    UP.....一下过两天结贴。。
    有没有人给个JPanel的CODE呀?
    谢谢了。。
      

  3.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    /*
     * Created on 2004-8-28
     *
     * To change the template for this generated file go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    /**
     * @author zhu_hb
     *
     * To change the template for this generated type comment go to
     * Window>Preferences>Java>Code Generation>Code and Comments
     */
    public class MySwing extends JFrame {
    Panel p;
    JRadioButton b1 = new JRadioButton("Metal"),
    b2 = new JRadioButton("Motif"),
    b3 = new JRadioButton("Windows");
    public MySwing() {
    super("Swing application");
    Container contentPane = getContentPane();
    p = new Panel();
    contentPane.add(p, BorderLayout.CENTER);
    }
    public static void main(String[] args) {
    final JFrame f = new MySwing();
    f.setBounds(100, 100, 300, 200);
    f.setVisible(true);
    f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    class Panel extends JPanel implements ActionListener {
    public Panel() {
    add(new JButton("JButton"));
    add(new JTextField("JTextField"));
    add(new JCheckBox("JCheckBox"));
    add(new JRadioButton("JRadioButton"));
    add(new JLabel("JLabel"));
    add(
    new JList(
    new String[] {
    "JList Item 1",
    "JList Item 2",
    "JList Item 3" }));
    add(new JScrollBar(SwingConstants.HORIZONTAL));
    ButtonGroup group = new ButtonGroup();
    group.add(b1);
    group.add(b2);
    group.add(b3);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    add(b1);
    add(b2);
    add(b3);
    }
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("Hello from Eclipse!", 60, 100);
    }
    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
    JRadioButton src = (JRadioButton) e.getSource();
    try {
    if ((JRadioButton) e.getSource() == b1)
    UIManager.setLookAndFeel(
    "javax.swing.plaf.metal.MetalLookAndFeel");
    else if ((JRadioButton) e.getSource() == b2)
    UIManager.setLookAndFeel(
    "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
    else if ((JRadioButton) e.getSource() == b3)
    UIManager.setLookAndFeel(
    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception ex) {
    }
    SwingUtilities.updateComponentTreeUI(getContentPane());
    }
    }
    }
      

  4.   

    因为我用过delphi
    我就把JPanel当成TPanel
        把JFrame当成TForm呵呵!不知对不!