我正在开发一个显示图像的应用程序,并从数据库中播放声音.我正在尝试决定是否使用单独的JFrame从GUI向数据库添加图像.
我只是想知道使用多个JFrame窗口是否是一个好习惯?
我正在关注如何创建自定义对话框的Oracle教程:http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
我有两个按钮:Save Object和Delete Object,点击它们时应该执行某段代码.不幸的是,我似乎无法向JOptionPane按钮添加任何ActionListener,因此当它们被点击时没有任何反应.
任何人都可以帮我告诉我如何做到这一点?这是我到目前为止对话框的类:
class InputDialogBox extends JDialog implements ActionListener, PropertyChangeListener {
private String typedText = null;
private JTextField textField;
private JOptionPane optionPane;
private String btnString1 = "Save Object";
private String btnString2 = "Delete Object";
/**
* Returns null if the typed string was invalid;
* otherwise, returns the string as the user entered it.
*/
public String getValidatedText() {
return typedText;
}
/** Creates the reusable dialog. */
public InputDialogBox(Frame aFrame, int x, int y) …Run Code Online (Sandbox Code Playgroud) 制作弹出窗口几秒钟后自动关闭所需的帮助.JOptionpane消息通常需要输入才能关闭,所以有没有其他方法来处理java中的自动关闭弹出窗口.请帮忙.提前致谢.
我有一个应用程序,它使用JDialog从用户获取输入,然后搜索文件,而不是浏览对话框,但使用元数据更专业.
这一切都很好.唯一的问题是我希望能够让用户输入搜索值,按Ok,并接收这些值来执行搜索和其他一些操作(来自打开对话框的调用类)而不关闭对话框?
有必要从调用类中执行这些操作,因为这是编辑器中插件的一部分.
基本上,简而言之,它有点像查找对话框在任何编辑器中的工作方式 - 当您从一个找到的项目跳到下一个项目时,查找对话框保持打开状态...
好像我错过了一些简单的东西,但我看不出怎么做.
编辑:
我根据Nick Rippe建议的教程在一个简单的测试应用程序中尝试了这个,但我认为我在某种程度上误解了它,因为我无法让它工作.我添加了一个带有getter和setter的字段,然后尝试获取它:
主要课程:
public class TestJFrames {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TestForm frame = new TestForm();
frame.setDefaultCloseOperation(frame.DO_NOTHING_ON_CLOSE);
frame.addPropertyChangeListener("fileSelected", new FileSelectedListener());
frame.setVisible(true);
}
}
class FileSelectedListener implements PropertyChangeListener {
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("TEST");
}
}
Run Code Online (Sandbox Code Playgroud)
从表单类:
private String fileSelected;
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setFileSelected("Test");
}
public String getFileSelected() {
return fileSelected;
}
public void setFileSelected(String fileSelected) {
this.fileSelected …Run Code Online (Sandbox Code Playgroud)