appication(AWT或SWING)里面有一个文本框,一个按钮 ,点击按钮,将文本框的内容在控制台打印输出。谢谢
1个回答
展开全部
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
public class OutPutFrame extends javax.swing.JFrame {
private JTextArea content;
private JButton output;
public static void main(String[] args) {
OutPutFrame inst = new OutPutFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public OutPutFrame() {
super();
initGUI();
}
private void initGUI() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
content = new JTextArea();
getContentPane().add(content, BorderLayout.CENTER);
content.setText("这里是内容");
}
{
output = new JButton();
getContentPane().add(output, BorderLayout.SOUTH);
output.setText("输出");
output.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.out.println(content.getText());
}
});
}
pack();
setSize(400, 300);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
public class OutPutFrame extends javax.swing.JFrame {
private JTextArea content;
private JButton output;
public static void main(String[] args) {
OutPutFrame inst = new OutPutFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public OutPutFrame() {
super();
initGUI();
}
private void initGUI() {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
content = new JTextArea();
getContentPane().add(content, BorderLayout.CENTER);
content.setText("这里是内容");
}
{
output = new JButton();
getContentPane().add(output, BorderLayout.SOUTH);
output.setText("输出");
output.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.out.println(content.getText());
}
});
}
pack();
setSize(400, 300);
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询