抱歉我的英文不好......我为我的Java GUI程序创建了一个登录界面。我停留在仪表板框架上...我不知道如果我点击登录按钮,它将被移动到一个新的框架...如果我进行此注册并仅在1个源java中登录就可以了文件?
全部,谢谢
这是我的代码
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class Dashboard extends JFrame implements ActionListener, KeyListener, MouseListener {
//JPanel
JPanel SignPane = new JPanel(new GridLayout(2,1));
JPanel LoginPane = new JPanel(new GridLayout(2,1));
//JLabel
JLabel gambar = new JLabel();
JLabel Userlbl = new JLabel("Username");
JLabel Passlbl = new JLabel("Password");
//TextField and Password
JTextField UserTxt = new JTextField(15);
JPasswordField PassTxt = new JPasswordField(15);
//JButton
JButton SigninBtn = new JButton("Sign In");
JButton SignupBtn = new JButton("Sign Up");
JButton SigninBtn2 = new JButton("Sign In");
JButton CancelBtn = new JButton("Cancel");
public Dashboard() {
super("Boutique");
gambar.setIcon(new ImageIcon("\\Untitled.jpg"));
add(gambar, BorderLayout.NORTH);
SignPane.add(SigninBtn);
SignPane.add(SignupBtn);
add(SignPane, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
setResizable(false);
SigninBtn.addMouseListener(this);
SignupBtn.addMouseListener(this);
}
public void signin() {
JFrame Signin = new JFrame();
LoginPane.add(Userlbl);
LoginPane.add(UserTxt);
LoginPane.add(Passlbl);
LoginPane.add(PassTxt);
LoginPane.add(SigninBtn2);
LoginPane.add(CancelBtn);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
Dashboard window = new Dashboard();
window.setVisible(true);
} catch (Exception e){
e.printStackTrace();
}
}
});
}
@Override
public void mouseClicked(MouseEvent e) {
if(e.getSource() == SigninBtn){
signin();
} else {
dispose();
}
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
我不明白你想要实现的目标。当你点击SigninBtn
时,你想要关闭旧窗口并打开一个新窗口吗?
顺便说一句,使用actionPerformed方法而不是mouseClicked,如果你没有使用MouseListener的任何其他方法,那么将其删除。
SigninBtn.addActionListener(this);
@Override
public void actionPerformed(ActionEvent e){
if(e.getSource().equals(SigninBtn)){
signin();
}
}