import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;public class MyJFrame extends JFrame
{
Container c ;
JMenu jm2 ,jm3;
public MyJFrame(String s)
{
super(s);
c = this.getContentPane();
JMenuBar jmb= new JMenuBar();
JMenu jm = new JMenu("login");
JMenuItem jmt = new JMenuItem("login");
jmt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Login lo = new Login();
c.add(lo);
c.validate();
}
});
JMenuItem jmt2 = new JMenuItem("add");
jmt2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Login lo = new Login();
lo.add(new Button("f"));
c.add(lo);
c.validate();
}
}); jm.add(jmt);
jm.add(jmt2);
jmb.add(jm);
this.setJMenuBar(jmb);
setSize(300,200);
setVisible(true);
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
}
public static void main(String[] s)
{
new MyJFrame("login");
}
}
class Login extends JPanel
{
public Login()
{
JPanel jp = new JPanel(new GridLayout(3,2));
JLabel jl = new JLabel("user:");
JLabel jl2 = new JLabel("password");
final JTextField jtf = new JTextField(10);
final JPasswordField jtf2 = new JPasswordField(10);
JButton jb = new JButton("submit"); jp.add(jl);
jp.add(jtf);
jp.add(jl2);
jp.add(jtf2);
jp.add(jb);
add(jp);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;public class MyJFrame extends JFrame
{
Container c ;
JMenu jm2 ,jm3;
public MyJFrame(String s)
{
super(s);
c = this.getContentPane();
JMenuBar jmb= new JMenuBar();
JMenu jm = new JMenu("login");
JMenuItem jmt = new JMenuItem("login");
jmt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Login lo = new Login();
c.add(lo);
c.validate();
}
});
JMenuItem jmt2 = new JMenuItem("add");
jmt2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Login lo = new Login();
lo.add(new Button("f"));
c.add(lo);
c.validate();
}
}); jm.add(jmt);
jm.add(jmt2);
jmb.add(jm);
this.setJMenuBar(jmb);
setSize(300,200);
setVisible(true);
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
}
public static void main(String[] s)
{
new MyJFrame("login");
}
}
class Login extends JPanel
{
public Login()
{
JPanel jp = new JPanel(new GridLayout(3,2));
JLabel jl = new JLabel("user:");
JLabel jl2 = new JLabel("password");
final JTextField jtf = new JTextField(10);
final JPasswordField jtf2 = new JPasswordField(10);
JButton jb = new JButton("submit"); jp.add(jl);
jp.add(jtf);
jp.add(jl2);
jp.add(jtf2);
jp.add(jb);
add(jp);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货