制作JPanel弹出窗口 [英] Making a JPanel Popup
问题描述
我正在为计算机开发一个应用程序,我有一个带有大量JPanel的JFrame,当我点击一个按钮时,我想要另一个JPanel弹出。
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
我已经尝试制作弹出菜单,但我不想要菜单,我想要一个窗口,我看不到找出怎么做:(
这可能很容易,但我没有足够的k nowledge in java
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
任何帮助?谢谢你们!
推荐答案
好的,为此你需要2个JFrame。第一个是按钮和所有内容,第二个是弹出的按钮。您将有3个类: Main
, classWhere1stJframeis
, ClassWhere2ndJframeis
。
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
.
这是 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);
}
}
这是 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);
}
}
}
}
这个是第2帧
:
import javax.swing.JFrame;
public class Frejm2 extends JFrame {
JFrame Frame2 = new JFrame();
public Frejm2()
{
super("Title");
}
}
这篇关于制作JPanel弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!