关于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);
}
} 展开
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);
}
} 展开
1个回答
展开全部
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);
}
}
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);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询