更新的jList当新建JFrame关闭 [英] Update Jlist when new Jframe closing

查看:112
本文介绍了更新的jList当新建JFrame关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到某种关于我的问题的信息,没有成功,
也许Stackowerflow是大还是我使用了错误的关键字。

I've tried to find some kind of information about my problem with no success, maybe Stackowerflow is to big or I'm using the wrong keywords.

不管怎样,我的问题是,我是怎样的一个新到Java从锋利的世界迁移。
我已经在项目开发一个简单的ServiceDesk软件。
我做了一个JFrame作为启动画面与一些按钮和一个JList,将显示的情况。一开始帧上的按钮中的是创造一个新的案例。该按钮将打开一个新的JFrame用户可以在其中输入所需的信息和一个按钮保存:将保存在列表中的信息。该列表将在不同的类来处理像下面。

Anyway, my problem is that I'm kind a new to Java migrating from the sharp world. I've an project in develop a simple servicedesk software. I've made a JFrame as Startscreen with some buttons and a JList that will display the cases. One of the buttons on the start frame is to create a new case. That button will open a new Jframe where the user can enter information needed and a button save: that will save the information in a list. The list will be handled in a different class like below.

开始打开的JFrame JFrame的情况下,将在listclass列表保存关闭本身并返回到开始的JFrame。
当用户返回到开始Jfram,我想JList的在开始的JFrame刷新自己并显示新的保存情况 - 这我不知道该怎么做。

Start Jframe opens case Jframe that will save in a list in the listclass close itself and return to Start jframe. When the user returns to the start Jfram and I want the Jlist in the start Jframe to refresh itself and display the new saved case - which I dont know how to do.

我想我做了一些事件有当的情况下的JFrame正在关闭,但我不知道如何应对开始写的JFrame

I guess I to do some event writing in the start Jframe that has to respond when the case Jframe is closing but I dont know how.

这是一种很难解释,但我没有上传图片的美誉。

It's kind a hard to explain, but I don't have the reputation to upload images.

推荐答案

我想你可能需要考虑创建,当您选择按钮,显示新的自定义对话框。这里是code的样片我保持方便的参考。这里的主要项目是显示的对话框静态方法,而事实上,该对话框是模式,因此执行暂停,直到关闭对话框,让你然后捕获对话框的保存数据,并从静态方法返回它的显示的对话框。以此为模板,并根据需要进行修改。更具体而言,响应是从该方法返回的值。在现实中,回应不会是一个简单的布尔,(我只是用它测试逻辑),但你的listClass包含所有你从对话框的输入控件收集的信息。到getUserInput()的调用是你想从你的主要的JFrame code做启动球滚动的东西。在actionPerformed()方法是在那里你会抓住从对话框控件中的数据并填充包含返回信息的类。

I think you might want to consider creating a new custom dialog box that displays when you select the button. Here's a sample piece of code I keep handy for reference. The main items here are the static method that displays the dialog, and the fact that the dialog is modal, so execution "pauses" until you close the dialog, allowing you to then capture the dialog's saved data and return it from the static method that displays the dialog. Use this as a template and modify as needed. More specifically, "response" is the value returned from the method. In reality, "response" will not be a simple boolean, ( I just used that to test the logic), but your listClass that contains all the information you collected from the dialog's input controls. The call to getUserInput() is what you'll want to do from your main JFrame code to start the ball rolling. The actionPerformed() method is where you'll grab the data from the dialog box controls and populate the class that contains the return info.

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class ConfirmDialog extends JDialog implements ActionListener
{   
        private boolean response = false;
        private JButton btnOK = new JButton("OK");
        private JButton btnCancel = new JButton("Cancel");
        private JPanel contentPane = new JPanel();

        public static boolean getUserInput()
        {
                    return new ConfirmDialog().showDialog();

        }

        private boolean showDialog()
        {
                    setVisible(true);
                    //next line executes only after dialog is disposed,                 since dialog is modal.
                    return response;
        }

        private ConfirmDialog()
        {
                         setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                    btnOK.setActionCommand("OK");
                    btnCancel.setActionCommand("Cancel");
                    btnOK.addActionListener(this);
                    btnCancel.addActionListener(this);
                    contentPane.add(btnOK);
                    contentPane.add(btnCancel);
                    setContentPane(contentPane);
                    setModal(true);
                    pack();

        }
        public void actionPerformed(ActionEvent e)
        {
                    if(e.getActionCommand().equals(btnOK.getActionCommand()))
                    {
                                response = true;
                    }
                    setVisible(false);
                    dispose();
        }

        /**
         * @param args
         */
        public static void main(String[] args) {
                    // TODO Auto-generated method stub
                    System.out.println(getUserInput());

        }

 }

这篇关于更新的jList当新建JFrame关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆