简体   繁体   English

如何从1jframe链接到另一个jframe

[英]how to link from 1jframe to another jframe

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
//import mainFrame.java;

public class login{
 public static void main(String [] args){
 JFrame f = new JFrame();
 final JLabel label= new JLabel();
 label.setBounds(20,150,220,70);
 final JPasswordField value = new JPasswordField();
 value.setBounds(130,75,100,30);
 JLabel l1 = new JLabel("Username :");
 l1.setBounds(50,25,140,30);
 JLabel l2 = new JLabel("Password :");
 l2.setBounds(50,75,70,30);
 JButton b = new JButton("Login");
  b.setBounds(100,120, 70,30);    
        final JTextField text = new JTextField();  
        text.setBounds(130,20, 100,30);    

                b.addActionListener(new ActionListener(){  
                public void actionPerformed(ActionEvent e) {       

                    /* JFrame  mainFrame = new JFrame();                   
                       mainFrame.setVisible(true);
                       //mainFrame.setSize(200, 300);

                       f.setVisible(false);
                         //this.f.dispose();*/



             }); 

             f.add(value); 
             f.add(l1); 
             f.add(label);
             f.add(l2); 
             f.add(b); 
             f.add(text);            
                f.setSize(300,300);    
                f.setLayout(null);    
                f.setVisible(true);  
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

 }
}

above one is my code for login panel so i can link to my mainframe panel but i am not able to link with my main frame what am i doing mistake i didn't get and i will be doing form validation later . 上面的是我的登录面板代码,因此我可以链接到大型机面板,但是我不能与大型机链接,我在做什么错误,我没有得到,我将在以后进行表单验证。

and here is my main frame which i want to call 这是我要呼叫的主要框架

import javax.swing.*;
import java.awt.event.*;
import java.util.*;

class mainFrame{
 public static void main(String args[]){

 JFrame f = new JFrame("Main Frame");


 f.setSize(400,500); 
 f.setVisible(true);//making the frame visible 
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   

 }
}

so how do i call this mainframe from login frame 所以我怎么从登录框架中调用这个大型机

So, you want to execute your mainframe after login validation. 因此,您想在登录验证后执行大型机。 All you have to do is to change your JButton 'b' ActionListener in your login class to this:- 您要做的就是将登录类中的JButton'b'ActionListener更改为:

b.addActionListener(new ActionListener(){  
public void actionPerformed(ActionEvent e){  
mainFrame MainFrame = new mainFrame();
//MainFrame.setVisible(true);     
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM