java怎样进行界面切换

您所在的位置:网站首页 java界面切换 java怎样进行界面切换

java怎样进行界面切换

2023-12-10 08:29| 来源: 网络整理| 查看: 265

其实很简单,就是如果登录界面的帐号密码输入正确,则登录窗口消失,出现主窗口。可这个主窗口如何出现啊?publicclassloginextendsJFrame{JFramemainm;JPaneljp1;JTextFieldjtf1,jtf...

其实很简单,就是如果登录界面的帐号密码输入正确,则登录窗口消失,出现主窗口。可这个主窗口如何出现啊?

public class login extends JFrame{

JFrame mainm;

JPanel jp1;

JTextField jtf1,jtf2;

JButton jb;

JLabel jl1,jl2;

static Statement st;

static{

try{

Class.forName("com.mysql.jdbc.Driver");

String url="jdbc:mysql://localhost:3306/student?"+"user=root&password=pass";

Connection conn=DriverManager.getConnection(url);

st=conn.createStatement();

}

catch(Exception e){}

}

public login(){

jtf1=new JTextField(10);

jtf2=new JTextField(10);

jl1=new JLabel("帐号名:");

jl2=new JLabel("密 码:");

jb=new JButton("登录");

jb.addActionListener(new Mysql());

Container container=getContentPane();

JPanel jp=new JPanel();

jp.setLayout(new FlowLayout());

jp.add(jl1);jp.add(jtf1);

jp.add(jl2);jp.add(jtf2);

jp.add(jb);

container.add(jp,BorderLayout.CENTER);

setTitle("登录");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(180,190);

setLocation(400,350);

setVisible(true);

}

class Mysql implements ActionListener{

public void actionPerformed(ActionEvent e){

try{

String str=jtf1.getText().trim();

String sq="select * from operator where username='"+str+"'";

ResultSet rs=st.executeQuery(sq);

if(rs.next()){

String str1=jtf2.getText();

String sq1="select * from operator where password='"+str1+"'";

ResultSet rs1=st.executeQuery(sq1);

if(rs1.next()){

setVisible(false);

new mainm();

return;

}

else{

JDialog dialog=new JDialog();

dialog.setSize(100,110);

dialog.setLocation(425,400);

dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

Container contentPane=dialog.getContentPane();

JLabel label=new JLabel(" 密码错误! ");

contentPane.add(label);

dialog.setVisible(true);

}

}

else{

JDialog dialog=new JDialog();

dialog.setSize(100,110);

dialog.setLocation(425,400);

dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

Container contentPane=dialog.getContentPane();

JLabel label=new JLabel(" 帐户名错误! ");

contentPane.add(label);

dialog.setVisible(true);

}

}

catch(Exception ee){}

}

}

public static void main(String []args)

{

new login();

}

}

展开



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3