• <bdo id='vL7LH'></bdo><ul id='vL7LH'></ul>

    <small id='vL7LH'></small><noframes id='vL7LH'>

  1. <legend id='vL7LH'><style id='vL7LH'><dir id='vL7LH'><q id='vL7LH'></q></dir></style></legend>

    <i id='vL7LH'><tr id='vL7LH'><dt id='vL7LH'><q id='vL7LH'><span id='vL7LH'><b id='vL7LH'><form id='vL7LH'><ins id='vL7LH'></ins><ul id='vL7LH'></ul><sub id='vL7LH'></sub></form><legend id='vL7LH'></legend><bdo id='vL7LH'><pre id='vL7LH'><center id='vL7LH'></center></pre></bdo></b><th id='vL7LH'></th></span></q></dt></tr></i><div id='vL7LH'><tfoot id='vL7LH'></tfoot><dl id='vL7LH'><fieldset id='vL7LH'></fieldset></dl></div>

    <tfoot id='vL7LH'></tfoot>

      java中的GUI“转到上一个/下一个"选项?

      GUI in java quot;go to previous/nextquot; option?(java中的GUI“转到上一个/下一个选项?)
      • <bdo id='8LdVe'></bdo><ul id='8LdVe'></ul>
            <tfoot id='8LdVe'></tfoot>

          • <i id='8LdVe'><tr id='8LdVe'><dt id='8LdVe'><q id='8LdVe'><span id='8LdVe'><b id='8LdVe'><form id='8LdVe'><ins id='8LdVe'></ins><ul id='8LdVe'></ul><sub id='8LdVe'></sub></form><legend id='8LdVe'></legend><bdo id='8LdVe'><pre id='8LdVe'><center id='8LdVe'></center></pre></bdo></b><th id='8LdVe'></th></span></q></dt></tr></i><div id='8LdVe'><tfoot id='8LdVe'></tfoot><dl id='8LdVe'><fieldset id='8LdVe'></fieldset></dl></div>

                  <tbody id='8LdVe'></tbody>

              1. <legend id='8LdVe'><style id='8LdVe'><dir id='8LdVe'><q id='8LdVe'></q></dir></style></legend>

                <small id='8LdVe'></small><noframes id='8LdVe'>

                本文介绍了java中的GUI“转到上一个/下一个"选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有办法可以选择转到上一个消息对话框或下一个?我有一个程序,在完成所有输入和数学计算后,会出现一个消息对话框,其中包含Person 1"的信息,然后按确定"并出现Person 2"的信息.如果有一个选项可以在不同的对话框之间导航,那就太好了.这是打印消息的程序部分.

                Is there a way to have an option to go the a previous message dialog box or a next one? I have a program where after all the input and math calculations is done, a message dialog box appears with the information for "Person 1" then you press ok and the one for "Person 2" appears. It would be nice if there could be an option to be able to navigate between the different dialog boxes. Here is the part of the program that prints the messages.

                for (i = 0; i < NumEmployees; i++)    
                {
                    JOptionPane.showMessageDialog(null, 
                            "Employee: " + names[i] + "
                " + 
                            "ID: " + data[i][0] + "
                " + 
                            "Hours worked: " + (data[i][1] + data[i][2]) + "
                " + 
                            "Overtime: " + data[i][2] + "hours" + "
                " + 
                            "Amount earned: " + payment[i]);    
                }
                

                推荐答案

                使用 Action 将功能和状态从组件中分离出来."在下面的示例中,操作将 indexupdate()List 更改为 JLabel.您的应用程序可能会从 List<Employee> 更新 JTextArea.

                Use Action "to separate functionality and state from a component." In the example below, the actions change the index and update() a JLabel from a List<String>. Your application might update a JTextArea from a List<Employee>.

                package gui;
                
                import java.awt.BorderLayout;
                import java.awt.EventQueue;
                import java.awt.event.ActionEvent;
                import java.util.ArrayList;
                import java.util.Arrays;
                import java.util.List;
                import javax.swing.AbstractAction;
                import javax.swing.JButton;
                import javax.swing.JFrame;
                import javax.swing.JLabel;
                
                /**
                 * @see http://stackoverflow.com/a/20116944/230513
                 */
                public class PrevNext {
                
                    private final List<String> list = new ArrayList<>(
                        Arrays.asList("Alpher", "Bethe", "Gamow", "Dirac", "Einstein"));
                    private int index = list.indexOf("Einstein");
                    private final JLabel label = new JLabel(list.get(index), JLabel.CENTER);
                
                    private void display() {
                        JFrame f = new JFrame("PrevNext");
                        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        f.add(new JButton(new AbstractAction("<Prev") {
                
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                if (--index < 0) {
                                    index = list.size() - 1;
                                }
                                update();
                            }
                        }), BorderLayout.LINE_START);
                        f.add(label);
                        f.add(new JButton(new AbstractAction("Next>") {
                
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                if (++index == list.size()) {
                                    index = 0;
                                }
                                update();
                            }
                        }), BorderLayout.LINE_END);
                        f.pack();
                        f.setLocationRelativeTo(null);
                        f.setVisible(true);
                    }
                
                    private void update() {
                        label.setText(list.get(index));
                    }
                
                    public static void main(String[] args) {
                        EventQueue.invokeLater(new Runnable() {
                
                            @Override
                            public void run() {
                                new PrevNext().display();
                            }
                        });
                    }
                }
                

                这篇关于java中的GUI“转到上一个/下一个"选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                <small id='QoU7t'></small><noframes id='QoU7t'>

                  <tbody id='QoU7t'></tbody>
                  • <bdo id='QoU7t'></bdo><ul id='QoU7t'></ul>

                    • <i id='QoU7t'><tr id='QoU7t'><dt id='QoU7t'><q id='QoU7t'><span id='QoU7t'><b id='QoU7t'><form id='QoU7t'><ins id='QoU7t'></ins><ul id='QoU7t'></ul><sub id='QoU7t'></sub></form><legend id='QoU7t'></legend><bdo id='QoU7t'><pre id='QoU7t'><center id='QoU7t'></center></pre></bdo></b><th id='QoU7t'></th></span></q></dt></tr></i><div id='QoU7t'><tfoot id='QoU7t'></tfoot><dl id='QoU7t'><fieldset id='QoU7t'></fieldset></dl></div>
                      <tfoot id='QoU7t'></tfoot>

                          <legend id='QoU7t'><style id='QoU7t'><dir id='QoU7t'><q id='QoU7t'></q></dir></style></legend>