到目前为止这是我的代码:
public static void main(String[] args){
JFrame frame = new JFrame("Breakout!");
frame.setLocation(300, 300);
//Making the menubar
JMenuBar mb = new JMenuBar();
frame.setJMenuBar(mb);
JMenu fileMenu = new JMenu("File");
mb.add(fileMenu);
JMenuItem newAction = new JMenuItem("About");
fileMenu.add(newAction);
newAction.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("open new window here");
}
});
BreakoutCourt c = new BreakoutCourt();
frame.add(c);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Run Code Online (Sandbox Code Playgroud)
我正在制作突围游戏.我想创建一个关于窗口,显示有关游戏的信息(比如,如何播放等等).我该怎么做呢?感谢您的帮助!我是Java Swing的新手,所以是的.
我在Android中为我的客户构建了大型应用程序.新项目是为Java构建相同的PC应用程序.所以我开始使用swing进行开发.在Android中构建时,我使用具有内容视图的活动的类,我可以在活动之间切换.在java中,我构建了多个扩展JFrame的类,我希望在它们之间切换.什么是正确的方法?
这是:
new_class.setVisible(true);
old_class.setVisible(false);
Run Code Online (Sandbox Code Playgroud)
正确的方法?
我需要一些简单的java应用程序的帮助,它使用两个jframe来获取一些输入参数.这是我的代码草图:
//second jframe, called when the button OK of the first frame is clicked
public class NewParamJFrame extends JFrame{
...
}
//first jframe
public class StartingJFrame extends JFrame{
private static NewParamJFrame newPFrame = null;
private JTextField gnFilePath;
private JButton btnOK;
public StartingJFrame(){
//..
initComponents();
}
private void initComponents(){
btnOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
EventQueue.invokeAndWait(new Runnable(){
public void run() {
try {
newPFrame = new NewParamJFrame();
newPFrame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
catch(InvocationTargetException e2) …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已被问到,但我找不到解决办法.
我创建了一个JFrame用于登录的按钮,我想在按下"Cont Nou"按钮打开一个带有新帐户的jpanel的新窗口,但不知道如何使初始帧消失并显示带有jpanel的帧.你有什么主意吗?谢谢!这就是我现在所做的:
这是JFrame登录:
public class LogIn extends JFrame implements ActionListener{
private JLabel labelEmail;
private JLabel labelParola;
private JTextField textFieldEmail;
private JPasswordField textFieldParola;
private JButton buttonLogin;
private JButton buttonContNou;
public LogIn (){
super();
this.setSize(400,200);
this.setTitle("Login");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setResizable(false);
this.setupComponents();
}
private void setupComponents(){
labelEmail = new JLabel("Email: ");
labelParola = new JLabel("Parola: ");
textFieldEmail = new JTextField();
textFieldParola = new JPasswordField();
buttonContNou = new JButton("Cont Nou");
buttonLogin = new JButton("Login");
labelEmail.setBounds(30,30,50,20);
labelParola.setBounds(30,70,50,20);
textFieldEmail.setBounds(100,30,185,20);
textFieldParola.setBounds(100,70,185,20);
buttonContNou.setBounds(185,110,100,20);
buttonLogin.setBounds(100,110,75,20); …Run Code Online (Sandbox Code Playgroud) 是否可以在应用程序中的任何窗口创建或关闭时得到通知?
目前我正在进行民意调查,Window.getWindows()但我更愿意收到通知.
是)我有的:
List<Window> previousWindows = new ArrayList<>();
while (true) {
List<Window> currentWindows = Arrays.asList(Window.getWindows());
for (Window window : currentWindows) {
if (!previousWindows.contains(window)) {
//window was created
}
}
for (Window window : previousWindows) {
if (!currentWindows.contains(window)) {
//window was closed
}
}
previousWindows = currentWindows;
Thread.sleep(1000);
}
Run Code Online (Sandbox Code Playgroud)
我想要的是什么:
jvm.addWindowListener(this);
@Override
public void windowWasDisplayed(Window w) {
//window was created
}
@Override
public void windowWasClosed(Window w) {
//window was closed
}
Run Code Online (Sandbox Code Playgroud) 我是GUI编程的新手,但需要创建一个多窗口GUI.有没有人知道任何在线的好教程或者你能否展示一个简单的代码,将启动2个窗口?
我有一个简单的GUI程序,可以JTable在某个时间点创建一个新窗口(包含一个).如果用户关闭JTable,主应用程序也会关闭.我该如何防止这种情况?它是否与它如何处理窗口关闭有关,或者我应该给它自己的线程,或者什么?
我正在尝试做一个简单的Jform并从另一个类调用它.我想在服务器客户端应用程序中使用此Jframe,但我不知道如何从另一个类打开JFrame类.
喜欢用户必须选择
1-打开Jframe.
2-退出.
那我做错了什么?
以下是代码:
Jframe类名为Calculas.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author user
*/
public class Calculas extends javax.swing.JFrame {
/**
* Creates new form Calculas
*/
public Calculas() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated …Run Code Online (Sandbox Code Playgroud) 我的代码创建了一个新数组并将其发送到chat(jFrame).
String info1[]=new String[3];
// username , userid , userid2 are variables
info1[0]=username4;
info1[1]=""+userid;
info1[2]=""+userid2;
chat.main(info1);
Run Code Online (Sandbox Code Playgroud)
但是我需要修改这段代码,以便在打开聊天jframe时使用它,然后不要打开一个新的jFrame.而是在聊天jframe中打开一个新选项卡.聊天框的代码是:
private void formWindowActivated(java.awt.event.WindowEvent evt) {
JScrollPane panel2 = new JScrollPane();
JTextArea ta=new JTextArea("");
ta.setColumns(30);
ta.setRows(19);
panel2.setViewportView(ta);
jTabbedPane1.add("Hello", panel2);
}
Run Code Online (Sandbox Code Playgroud) 我总是想知道如何制作一个包含多个JFrame的程序.我的意思是我只想要一个类来处理所有的GUI和东西,但我怎么能有效地做到这一点?很多教程都说我们通过继承JFrame来制作JFrame.但如果我想要很多帧呢?
例如:带有一些选项的一帧中的应用程序标题菜单是一帧主要工作应用程序是一帧像游戏中一样.
但我不确定我是否与JPanel有关?我对2完全感到困惑.我只想要一个不移动的框架,但基本上框架的内容正在发生变化.例如,当我点击START时,它将变为框架的游戏风格.