
用java实现:一个窗口包含文本行和标签,在文本行中输入一段文字并按ENTER键后,这段文字将显示在标签上 10
1个回答
展开全部
package Test10;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Test2 {
private static JFrame frame = new JFrame();
private static JPanel panel = new JPanel();
private static JLabel label = new JLabel("默认为空");
private static JTextField text = new JTextField(18);
class TextAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
Test2.label.setText(Test2.text.getText());
}
}
public static void main(String[] args) {
panel.add(label);
panel.add(text);
frame.add(panel);
text.addActionListener(new Test2().new TextAction());
frame.setBounds(20, 50, 600, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(3);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Test2 {
private static JFrame frame = new JFrame();
private static JPanel panel = new JPanel();
private static JLabel label = new JLabel("默认为空");
private static JTextField text = new JTextField(18);
class TextAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
Test2.label.setText(Test2.text.getText());
}
}
public static void main(String[] args) {
panel.add(label);
panel.add(text);
frame.add(panel);
text.addActionListener(new Test2().new TextAction());
frame.setBounds(20, 50, 600, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(3);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询