当我启动程序时,我创建了MainFrame.当我点击"搜索"按钮时,我会显示另一个JFrame.如果它在搜索上获得结果,则目标是填充MainFrame中的信息.
一切正常.但是为了能够显示信息,我必须重新创建MainFrame.这意味着两个MainFrame保持开放状态.
我该如何隐藏第一个?
设置我只有MainFrame和一个带有搜索表单的对话框.
当我点击搜索对话框上的确定按钮时,我有一些信息.
在MainFrame类我知道信息就在那里.
我在文本字段等上有settext ...在最后一行我有"setvisible(true)".
但他们仍然是空白!为什么??
任何人都可以在这里发布一个例子,怎么做?请
我只是搜索所有选项,但我无法解决.
我有一个应用程序,当按下同名按钮时,会创建一个新窗口(让我们称之为Cuprins).我遇到的问题是,当我关闭新窗口时,它也会关闭主窗口.关闭Cuprins窗口时,有没有关闭主窗口?
我有一个任务来创建一个JInternalFrame可以调用我的applet工作的多个(最后一个分配调用SpherePainter)并且可以计算在其中运行了多少'applet' JinternalFrame.
[小程序在另一个内部运行JInternalFrame]
public class MyInternalFrame extends JInternalFrame {
static int openFrameCount = 0;
static final int xOffset = 30, yOffset = 30;
public MyInternalFrame() {
super("SpherePainter #" + (++openFrameCount),
true,
true,
true,
true);
setSize(500,500);
//Set the window's location.
setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
SpherePainterApplet sp = new SpherePainterApplet ();
sp.init();
this.add(sp);
}
Run Code Online (Sandbox Code Playgroud)
}
我可以毫无问题地调用applet,但我无法计算它们中有多少是"实际"运行的.
我的方法是checkApp++在创建一个applet和checkApp--关闭一个applet 时.有没有办法使用关闭按钮(X)或类似的听众?
我正在尝试构建一个带有2个按钮的主GUI的小程序.一个按钮关闭程序,另一个按钮我打开一个新的JPanel,它将有文本字段等.
我希望能够制作按钮,使它们看起来像普通的应用程序按钮,我想,漂亮和正方形,相同的大小等等,我不知道如何做到这一点.
此外,我不确定如何通过按钮单击打开新的JFrame.
GUI代码:
package practice;
public class UserInterface extends JFrame {
private JButton openReportSelection = new JButton("Open new Window");
private JButton closeButton = new JButton("Close Program");
private JButton getCloseButton() {
return closeButton;
}
private JButton getOpenReportSelection() {
return openReportSelection;
}
public UserInterface() {
mainInterface();
}
private void mainInterface() {
setTitle("Program Information Application");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel centerPanel = new JPanel(new GridLayout(0, 3));
centerPanel.add(openReportSelection);
centerPanel.add(closeButton);
getCloseButton().addActionListener(new Listener());
add(centerPanel, BorderLayout.CENTER);
setSize(1000, 200);
setVisible(true);
}
private void addReportPanel() {
JPanel reportPanel = createNewPanel();
getContentPane().add(reportPanel, …Run Code Online (Sandbox Code Playgroud) 所以我有这个代码.我正在尝试实现点击以保存JMenuBar并点击加载.我无法序列化JPanel.
我怎么能保存当前的情节视图?布局设置为AbsoluteLayout所以GroupLayout问题不是问题.我已阅读谷歌搜索,我知道这不推荐,但我怎么能保存并加载它?
package tester;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Line2D;
import java.awt.image.BufferedImage;
import javax.swing.*;
import static tester.Plot.XMAX;
import static tester.Plot.XMIN;
import static tester.Plot.YMAX;
import static tester.Plot.YMIN;
import java.io.*;
/**
*
* @author Sana
*/
public class NewJFrame2 extends javax.swing.JFrame{
public class Plot extends JPanel implements java.io.Serializable {
public double xmin=0;
public double xmax=0;
public double ymin=0;
public double ymax=0;
public static final int XMIN = 45;
public static …Run Code Online (Sandbox Code Playgroud) 我是Java的新手.
然而,我打算这样做;
1.一个主JFrame1和
2.在JFrame1中,我有一个用于JFrame2.setVisible(true)的Button1 ; &
3.另一个JFrame2.
我需要知道的是:当用户点击JFrame1-> Button1时
如何使JFrame1完全不活动,以便用户在JFrame2处于活动状态时无法单击JFrame1上的按钮或聚焦JFrame1.
我需要设置,当JFrame2关闭时,所有上述内容都可以点击/聚焦.
谢谢 !

这是我的节目的图片.所有这些JMenuItem都在一个JFrame中,我为每个JFrame添加了JPanel.当用户单击一个JMenuItem时,所有JPanels都将是不可见的,只有相应的JPanel才能工作.
这是一个好方法吗?我的班级很庞大.添加功能之前是5000行.
如何将在一个JFrame的文本字段中输入的值作为输入参数传递给其他JFrame?
在第一次进入用户名和密码JFrame通过JTextFields..
String usr = jTextField2.getText();
String pass = jTextField3.getText();
Run Code Online (Sandbox Code Playgroud)
相同的用户名和密码应在第四帧中作为输入给出,每个帧在按钮点击时被重定向到其他帧
我制作了一个J1包含JButton 的JFrame(称之为).单击该按钮时,J2将打开一个新的JFrame(调用它).
J1还有一个包含的ArrayList J2,以及所有其他已打开的Jframe.
J2被设定为DISPOSE_ON_CLOSED
我为设置J2一个的windowClosed()方法.为了测试,我在循环里面的JFrame扔ArrayList,直到我获得了当前的J2刚关闭,而令人惊讶的,当我做J2.setVisisble(true)了J2窗口的回报!
我还检查了扔任务管理器,并看到虽然开了一个新的J2,会使整个程序消耗更多的RAM,关闭每个J2在任务管理器上没有显示太大差异,它看起来不像任何内存被释放.看起来几秒后内存消耗会回到"正常"状态,所以我怀疑是否有直接与之相关的事情J2.
每次启动新内容时我都尝试打印(System.out.print)所有ArrayList内容J2,打开一个窗口,关闭它,打开一个新窗口后,我得到以下的messgae:
home.ATMmachine[frame0,252,198,620x420,invalid,hidden,layout=java.awt.BorderLayout,title=ATM Machine No.1,resizable,normal,defaultCloseOperation=DISPOSE_ON_CLOSE,rootPane=javax.swing.JRootPane[,9,38,602x373,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
Run Code Online (Sandbox Code Playgroud)
这意味着J2没有完全删除!
dispose()假设JFrame 方法
释放此Window,其子组件及其所有子组件使用的所有本机屏幕资源.也就是说,这些组件的资源将被销毁,它们使用的任何内存都将返回给操作系统,并且它们将被标记为不可显示.
所以我只是错了,并且框架将被删除并且总和更晚.
如果没有,那么我如何删除框架,以便引用它就像引用null?
java ×10
swing ×10
jframe ×5
jpanel ×2
applet ×1
button ×1
cardlayout ×1
frame ×1
jdialog ×1
jlist ×1
jtextfield ×1
netbeans ×1
parent-child ×1
window ×1