关于java的JTextArea显示问题:把str对象在JTextArea对象中显示出来,麻烦改下代码,文本框可以不用管它 5

publicclassJHextendsJFrame{privateJPanelcontentPane;staticprivateJTextAreajta;private... public class JH extends JFrame {

private JPanel contentPane;
static private JTextArea jta;
private JTextField textField;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JH frame = new JH();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
// jta = new JTextArea();
// JScrollPane jspane = new JScrollPane(jta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}

/**
* Create the frame.
*/
public JH() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JTextArea textArea = new JTextArea();
textArea.setBounds(10, 18, 424, 112);
textArea.setAutoscrolls(true);
contentPane.add(textArea);

JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String str="你是谁?";
jta =new JTextArea(str);
// textField.setText(str);

} catch (Exception e1) {
System.out.println("错误");
}
}
});
btnNewButton.setBounds(70, 171, 93, 23);
contentPane.add(btnNewButton);

textField = new JTextField();
textField.setBounds(36, 140, 77, 21);
contentPane.add(textField);
textField.setColumns(10);
}

}
展开
 我来答
百度网友0f0f1f5
2012-06-06 · 贡献了超过139个回答
知道小有建树答主
回答量:139
采纳率:0%
帮助的人:130万
展开全部
public class JH extends JFrame {

private JPanel contentPane;
static private JTextArea jta;
private JTextField textField;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JH frame = new JH();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
// jta = new JTextArea();
// JScrollPane jspane = new JScrollPane(jta,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}

/**
* Create the frame.
*/
public JH() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JTextArea textArea = new JTextArea();
textArea.setBounds(10, 18, 424, 112);
textArea.setAutoscrolls(true);
contentPane.add(textArea);

JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String str="你是谁?";
//jta =new JTextArea(str);
textArea.setText(str);
// textField.setText(str);

} catch (Exception e1) {
System.out.println("错误");
}
}
});
btnNewButton.setBounds(70, 171, 93, 23);
contentPane.add(btnNewButton);

textField = new JTextField();
textField.setBounds(36, 140, 77, 21);
contentPane.add(textField);
textField.setColumns(10);
}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式