I'm developing an app for computer, and i have a JFrame with a lot of JPanel on it, and when i click on a button, i want another JPanel to popup.
Example: When i click on this button
http://i62.tinypic.com/c2fzr.jpg
I want this window to popup
http://i62.tinypic.com/2qi0in7.jpg
I already tried making a popup menu, but i don't want a menu, i want a window, and i can't seen to find out how to do it :(
It's probably easy, but i don't have enough knowledge in java
Any help? thanks guys!
Ok so,for this you will need 2 JFrames. First one is where the buttons and everything is and the second one is the one that will popup. You will have 3 classes: Main
, classWhere1stJframeis
, ClassWhere2ndJframeis
.
This is main
:
package proba;
import javax.swing.JFrame;
public class mejn {
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame1 frejm = new Frame1();
frejm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frejm.setVisible(true);
frejm.setSize(250, 300);
}
}
This is Frame1
:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Frame1 extends JFrame {
JFrame Frame = new JFrame();
JButton Button1 = new JButton();
public Frame1()
{
super("The title");
Frame = new JFrame();
Button1 = new JButton();
Frame.add(Button1);
thehandler handler = new thehandler();
Button1.addActionListener(handler);
}
private class thehandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==Button1)
{
Frejm2 frejm = new Frejm2();
frejm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frejm.setVisible(true);
}
}
}
}
This is Frame2
:
import javax.swing.JFrame;
public class Frejm2 extends JFrame {
JFrame Frame2 = new JFrame();
public Frejm2()
{
super("Title");
}
}
that is not just a panel you want to pop up that would be considered a whole other frame. I would suggest making a different JFrame class that when the button is clicked instantiates the other frame.