解决方案 »

  1.   

    如下
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JRadioButton;public class MyFrame extends JFrame{

    public void service(){
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = getContentPane();

    final JRadioButton button1 = new JRadioButton("好好学swing");
    final Color colorBefore = button1.getBackground();
    button1.setBackground(Color.ORANGE);

    JButton button2 = new JButton("弹出新窗口");
    button2.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    JFrame f = new JFrame();
    f.setSize(400,300);
    JLabel label = new JLabel("我是新窗口");
    f.add(label);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
    }
    });

    add(button1,BorderLayout.NORTH);
    add(button2,BorderLayout.WEST);

    pack();
    setLocationRelativeTo(null);
    setVisible(true);
    }


    public static void main(String[] args) {
    MyFrame frame = new MyFrame();
    frame.service();
    }

    }
      

  2.   

    你的意思是比如点击这个查询成绩,会谈出一个新的窗口,然后再新的窗口上查询,是这样吧
    好久没做这个了,有点模糊,给你说个思路把
    1:首先自己查阅一下JDK文档查询一下swing里的eventListener这些类,找到其中一个与新窗口有关的,然后继承,重写里面的方法
    2:给你的JButton这个按钮,添加对应的事件监听器,里面传入上面继承的那个类的实例,可以用匿名内部类的方式传入即可
    由于没怎么关注过Swing所以只能帮助这么多了