Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java gui swing按用户操作输入_Java_User Interface_Io - Fatal编程技术网

java gui swing按用户操作输入

java gui swing按用户操作输入,java,user-interface,io,Java,User Interface,Io,我是新来的。 我正在尝试为我已经制作好的java程序创建一个gui。 我想让用户输入端口号和文件的位置,从那里我想使用我已经制作的程序来完成其余的工作。 我对如何从用户输入中获取值并实现到程序感到困惑 这是我的程序框架 public class TcpServerCompareCSV extends Frame implements ActionListener , WindowListener { private Label lblPort; // declare compo

我是新来的。 我正在尝试为我已经制作好的java程序创建一个gui。 我想让用户输入端口号和文件的位置,从那里我想使用我已经制作的程序来完成其余的工作。 我对如何从用户输入中获取值并实现到程序感到困惑

这是我的程序框架

public class TcpServerCompareCSV extends Frame implements ActionListener , WindowListener  {


   private Label lblPort;    // declare component Label
   private TextField tfPort; // declare component TextField    
   private int port;     // port number



   /** WindowEvent handlers */
   // Called back upon clicking close-window button
   @Override
   public void windowClosing(WindowEvent e) {
      System.exit(0);  // terminate the program
   }




   //constructor for frame
   public TcpServerCompareCSV () {
      setLayout(new FlowLayout());
         // "this" Frame sets its layout to FlowLayout, which arranges the components
         //  from left-to-right, and flow to next row from top-to-bottom.

      lblPort = new Label("Port"); // construct Label
      add(lblPort);                   // "this" Frame adds Label

      tfPort = new TextField("0", 10); // construct TextField
      tfPort.setEditable(true);       //edit text
      add(tfPort);                     // "this" Frame adds tfCount



      tfPort.addActionListener(this); // for event-handling

      setTitle("compare");  // "this" Frame sets title
      setSize(250, 100);        // "this" Frame sets initial window size
      setVisible(true);         // "this" Frame shows


      addWindowListener(this);
        // "this" Frame fires WindowEvent its registered WindowEvent listener
        // "this" Frame adds "this" object as a WindowEvent listener

   }




   /** ActionEvent handler - Called back when user clicks the button. */
   @Override
   public void actionPerformed(ActionEvent evt) {
    // Get the String entered into the TextField tfPort, convert to int
      port = Integer.parseInt(tfPort.getText());

   }





   /** The entry main() method */

public static void main(String[] args) throws IOException{

      // Invoke the constructor to setup the GUI, by allocating an instance
    TcpServerCompareCSV app = new TcpServerCompareCSV();

你的代码不完整,所以我不得不猜测一些事情,特别是关于你“已经制作”的程序的样子

假设在一个类中有一个命令行程序,它的开头类似于:

public class AlreadyMade
{
  public static void main(String[] arguments)
  {
    AlreadyMade am = new AlreadyMade();
    am.goToIt(arguments[0], arguments[1]);
  }

  public void goToIt(String s1, String s2)
  {
    // insert logic here for what to do with your port number and location
  }
}
在这种情况下,您可以从GUI调用goToIt()方法,可能是从actionPerformed方法调用,方法与您在AlreadyMade类中从main调用它的方法相同:

...
AlreadyMade am = new AlreadyMade();
am.goToIt(tfPort.getText(), tfFileLocation.getText());  // assume tfFileLocation, etc.
...
我也不得不猜测这是你想知道的;如果没有,至少你知道你想知道的是什么,并且可以完善这个问题