高手求解swing组件不能使用
为什么 姓名写改器 的JTextFile无法显示?程序代码:
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class qwe extends JFrame { JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); public qwe(){ JTextField jtf=new JTextField(10); jp1.setLayout(new GridLayout(1, 2)); jp1.add(new JLabel("姓名")); jp1.add(jtf); jp2.setLayout(new GridLayout(1, 2)); jp2.add(new JLabel("年级")); jp2.add(jtf); JFrame xhayFrame = new JFrame(); JButton name = new JButton("姓名修改器"); JButton classof = new JButton("年级修改器"); xhayFrame.add(name); xhayFrame.add(classof); xhayFrame.setLayout(new FlowLayout()); xhayFrame.setVisible(true); xhayFrame.pack(); xhayFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); name.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JFrame xasFrame = new JFrame(); xasFrame.add(jp1); xasFrame.pack(); xasFrame.setVisible(true); } }); classof.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JFrame xasFrame = new JFrame(); xasFrame.add(jp2); xasFrame.pack(); xasFrame.setVisible(true); } }); } public static void main(String[] args){ new qwe(); } }