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

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

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

      1. <legend id='AGhc5'><style id='AGhc5'><dir id='AGhc5'><q id='AGhc5'></q></dir></style></legend>
      2. java中的GUI“转到上一个/下一个"选项?

        时间:2023-09-29
          <legend id='PApMM'><style id='PApMM'><dir id='PApMM'><q id='PApMM'></q></dir></style></legend>

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

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

          1. <tfoot id='PApMM'></tfoot>

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

                  本文介绍了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“转到上一个/下一个"选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何获得对话框大小? 下一篇:向 Dialog 添加多项选择并使其正常运行

                  相关文章

                  最新文章

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

                  1. <small id='il18K'></small><noframes id='il18K'>

                      <legend id='il18K'><style id='il18K'><dir id='il18K'><q id='il18K'></q></dir></style></legend>
                    1. <tfoot id='il18K'></tfoot>
                        <bdo id='il18K'></bdo><ul id='il18K'></ul>