How to Make a Jframe Button Open Another Jframe Class in Netbeans

How to make Jframe button open another Jframe screen in Netbeans

Double Click the Register Button in the NETBEANS or add the Event Listener on Click Event (ActionListener)

btnLogin.addActionListener(new ActionListener() 
{
public void actionPerformed(ActionEvent e) {
this.setVisible(false);
new FrmMain().setVisible(true); // Main Form to show after the Login Form..
}
});

Java: how to open one Jframe from another Jframe which is not in the same file but in the same package;

So your problem is to open a new frame from a departure frame ? It's simple you just need to instanciate a new frame object like in the following :

JFrame home2 = new Home2(); // don't forget the import since it's a custom made Frame ;)
home2.setVisible(true);

Now you want that to be done when you click on a JButton. To do so you need to add an ActionListener, using an anonyous class, to the JButton with the previous code.

jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
//stuff
}
});

See the addActionListener() method of JButton and the ActionListener.

Calling a JFrame method from another JFrame on Button Click

Yes, you are right. The line Main_Window mw = new Main_Window(); is definitely wrong.

Better solution is:

public class UpdateWindow extends JFrame {
private final MainWindow mainWindow;
public UpdateWindow(MainWindow mainWin) {
mainWindow = mainWin;
}
private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) {
quantity = Integer.parseInt(quantityTextField.getText());
price = Integer.parseInt(priceTextField.getText());
mainWindow.putDataIntoTable(price,3,2);
}
}

Also you need to correct the call of constructor for UpdateWindow

private void updateBtnActionPerformed(java.awt.event.ActionEvent evt) {                                         
UpdateWindow newWindow = new UpdateWindow(this);
newWindow.setVisible(true);
newWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

Please note: I've corrected your class names as it proposed by Java naming convention. Main_Window -> MainWindow, Update_Window -> UpdateWindow.

When my suggestion don't solve your problems, please provide a [mcve] so we can better identify your problems.

JFrame, trying to make button run another class

What you want is to launch your class as a Thread

To launch your class CopyDir as a thread, make it implement Thread, change your main method signature to this :

public void run() {
//Your code
}

Also, to pass parameters to your thread, add a constructor in your CopyDir class that takes the parameters you have and stores them as attributes, to be able to get it from your method.

Then, to launch the thread from your event listeners :

 CopyDir myCopyThread = new CopyDir(inputPath,outputPath);
myCopyThread.start();

This code will create a thread that starts running CopyDir in the run() method

Java JFRAME button then new gui

I am still learning, but want to try and help.I would try making a new JFrame in the actionPerformed method of the listener. I also would probably make separate classes for your button action listeners otherwise you won't be able to perform separate task. I.E.

 class button1Listener implements ActionListener {
public void actionPerformed(ActionEvent ev){
JFrame frame = new JFrame();
(ETC CODE...)
}
}


Related Topics



Leave a reply



Submit