簡體   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); 

 }
}

上面的是我的登錄面板代碼,因此我可以鏈接到大型機面板,但是我不能與大型機鏈接,我在做什么錯誤,我沒有得到,我將在以后進行表單驗證。

這是我要呼叫的主要框架

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);   

 }
}

所以我怎么從登錄框架中調用這個大型機

因此,您想在登錄驗證后執行大型機。 您要做的就是將登錄類中的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