public void btnConfirm_actionPerformed(ActionEvent e) {
String userName = txtUserName.getText()//取得帐号
String pwd = txtPwd.getText()//取得密码
if(userName.equals("admin") &&pwd.equals("T806"))
{
javax.swing.JOptionPane.showMessageDialog(this,"成功登陆")
JumpFrame jf = new JumpFrame()//用另一个面板创建的对象
jf.setVisible(true)//打开那个创建的面板
this.dispose()//关闭当前登陆窗体
return
}
else
{
javax.swing.JOptionPane.showMessageDialog(this,"用户名或密码错误")
return
}
这样就可以实现窗体与窗体之间的互换了。
import javax.swing.*import java.awt.*
import java.awt.event.*
public class NewJFrame extends JFrame{
private JFileChooser chooser
private JTextField testfield
JPanel card
JPanel card2
JPanel cards
CardLayout loy = new CardLayout()//加了这一行
public NewJFrame(){
this.setTitle("aaa")
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
createPanel(this.getContentPane())
}
private void createPanel(Container pane){
card = new JPanel()
JButton button0 = new JButton("xxxxxxxxx")
card.add(button0)
card2 = new JPanel()
testfield = new JTextField("",20)
card2.add(testfield)
JButton button = new JButton("选择文件目录")
button.addActionListener(new CreateAdd_field_actionAdapter(this))
card2.add(button)
JButton button2 = new JButton("下一步")
button2.addActionListener(new CreateAdd_next_actionAdapter(this))
card2.add(button2)
cards = new JPanel(loy)//这里改了
cards.add(card2, "TEXTPANEL")
cards.add(card, "BUTTONPANEL")
pane.add(cards, BorderLayout.CENTER)
}
void field_actionPerformed(ActionEvent e){
}
void next_actionPerformed(ActionEvent e){
//CardLayout loy = new CardLayout()//删了这一行
loy.show(cards, "BUTTONPANEL")
}
public static void main(String arg[]){
NewJFrame frame = new NewJFrame()
frame.setLocation(300, 200)
frame.setSize(400, 300)
frame.setVisible(true)
}
}
class CreateAdd_field_actionAdapter implements ActionListener{
private NewJFrame adaptee
CreateAdd_field_actionAdapter(NewJFrame adaptee) {
this.adaptee = adaptee
}
public void actionPerformed(ActionEvent e) {
adaptee.field_actionPerformed(e)
}
}
class CreateAdd_next_actionAdapter implements ActionListener{
private NewJFrame adaptee
CreateAdd_next_actionAdapter(NewJFrame adaptee) {
this.adaptee = adaptee
}
public void actionPerformed(ActionEvent e) {
adaptee.next_actionPerformed(e)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)