java中在一个frame中按按钮跳到另一个frame中
这是一个frameimportjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclasslogin...
这是一个frame
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class login extends JFrame {
static final int WIDTH=300;
static final int HEIGHT=200;
public login(){
setTitle("欢迎使用ZDNF电子商务系统");
setSize(WIDTH,HEIGHT);
Container con=getContentPane();
JLabel label1=new JLabel("姓名:");
JTextField textField1=new JTextField(10);
textField1.setMaximumSize(textField1.getPreferredSize());
Box hbox1=Box.createHorizontalBox();
hbox1.add(label1);
hbox1.add(Box.createHorizontalStrut(20));
hbox1.add(textField1);
JLabel label2=new JLabel("密码:");
JPasswordField textField2=new JPasswordField(10);
textField2.setMaximumSize(textField2.getPreferredSize());
Box hbox2=Box.createHorizontalBox();
hbox2.add(label2);
hbox2.add(Box.createHorizontalStrut(20));
hbox2.add(textField2);
JButton OK=new JButton("登录");
JButton Cancel=new JButton("忘记密码?");
JButton resistered=new JButton("新用户注册");
Box hbox3=Box.createHorizontalBox();
hbox3.add(OK);
hbox3.add(Cancel);
hbox3.add(resistered);
OK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event){
studentmanageframe studentframe=new studentmanageframe ();
}
});
Box vbox=Box.createVerticalBox();
vbox.add(hbox1);
vbox.add(hbox2);
vbox.add(Box.createVerticalGlue());
vbox.add(hbox3);
con.add(vbox,BorderLayout.CENTER);
}
public static void main(String[] args){
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=screenSize.width;
int height=screenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
login framel=new login();
framel.setLocation(x,y);
framel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
framel.show();
}
}
这个另一个frame
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.*;
class studentmanageframe extends JPanel {
private static final long seriaVersionUID= 1L;
static final int WIDTH=300;
static final int HEIGHT=200;
JFrame studentframe;
public studentmanageframe(){
studentframe=new JFrame();
studentframe.setTitle("新用户注册界面");
studentframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
studentframe.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=screenSize.width;
int height=screenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
studentframe.setLocation(x,y);
studentframe.setVisible(false);
studentframe.add(this, BorderLayout.CENTER);
JButton computerone=new JButton("...."); 展开
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class login extends JFrame {
static final int WIDTH=300;
static final int HEIGHT=200;
public login(){
setTitle("欢迎使用ZDNF电子商务系统");
setSize(WIDTH,HEIGHT);
Container con=getContentPane();
JLabel label1=new JLabel("姓名:");
JTextField textField1=new JTextField(10);
textField1.setMaximumSize(textField1.getPreferredSize());
Box hbox1=Box.createHorizontalBox();
hbox1.add(label1);
hbox1.add(Box.createHorizontalStrut(20));
hbox1.add(textField1);
JLabel label2=new JLabel("密码:");
JPasswordField textField2=new JPasswordField(10);
textField2.setMaximumSize(textField2.getPreferredSize());
Box hbox2=Box.createHorizontalBox();
hbox2.add(label2);
hbox2.add(Box.createHorizontalStrut(20));
hbox2.add(textField2);
JButton OK=new JButton("登录");
JButton Cancel=new JButton("忘记密码?");
JButton resistered=new JButton("新用户注册");
Box hbox3=Box.createHorizontalBox();
hbox3.add(OK);
hbox3.add(Cancel);
hbox3.add(resistered);
OK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent Event){
studentmanageframe studentframe=new studentmanageframe ();
}
});
Box vbox=Box.createVerticalBox();
vbox.add(hbox1);
vbox.add(hbox2);
vbox.add(Box.createVerticalGlue());
vbox.add(hbox3);
con.add(vbox,BorderLayout.CENTER);
}
public static void main(String[] args){
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=screenSize.width;
int height=screenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
login framel=new login();
framel.setLocation(x,y);
framel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
framel.show();
}
}
这个另一个frame
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import javax.swing.*;
class studentmanageframe extends JPanel {
private static final long seriaVersionUID= 1L;
static final int WIDTH=300;
static final int HEIGHT=200;
JFrame studentframe;
public studentmanageframe(){
studentframe=new JFrame();
studentframe.setTitle("新用户注册界面");
studentframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
studentframe.setSize(WIDTH,HEIGHT);
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int width=screenSize.width;
int height=screenSize.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
studentframe.setLocation(x,y);
studentframe.setVisible(false);
studentframe.add(this, BorderLayout.CENTER);
JButton computerone=new JButton("...."); 展开
6个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询