如何在jframe中添加用于输入用户输入的位置?

时间:2014-05-20 16:31:02

标签: java swing jframe

我希望在我创建的程序中有用户输入,在java的jframe中有任何方式可以让用户输入内容。

3 个答案:

答案 0 :(得分:0)

您可以使用文本字段,如JTextField,JFormattedTextField等。有关详细信息,请参阅Swing上的Oracle documentation

答案 1 :(得分:0)

几个Java Swing GUI组件允许您在JFrame中使用的用户输入。例如,文本字段提供格式化文本输入或密码字段行为。我想你应该熟悉swing GUI组件,以便建立友好的用户界面。

答案 2 :(得分:-1)

类似的东西:

package test20may2014;
import java.awt.BorderLayout;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.*;
public class Test20may2014 implements WindowListener{
static JTextArea foo;
static JTextField bar;
public static void main(String[] args) {
    JFrame jframe = new JFrame("Test20May2014");
    jframe.addWindowListener(new Test20may2014());
    foo = new JTextArea(10,10);
    bar = new JTextField(10);
    jframe.getContentPane().add(foo, BorderLayout.NORTH);
    jframe.getContentPane().add(bar, BorderLayout.CENTER);
    jframe.pack();
    jframe.setVisible(true);
}
@Override
public void windowActivated(WindowEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public void windowClosed(WindowEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public void windowClosing(WindowEvent arg0) {
    System.out.println(foo.getText());
    System.out.println(bar.getText());
    System.exit(0);
    // TODO Auto-generated method stub

}
@Override
public void windowDeactivated(WindowEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public void windowDeiconified(WindowEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public void windowIconified(WindowEvent arg0) {
    // TODO Auto-generated method stub

}
@Override
public void windowOpened(WindowEvent arg0) {
    // TODO Auto-generated method stub

}

}