import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WindowActionEvent extends JFrame implements ActionListener
{
JTextField text;
JTextArea textShow;
JButton button;
public WindowActionEvent()
{
setLayout(new FlowLayout());
text=new JTextField(10);
add(text);
button=new JButton("确定");
add(button);
button.addActionListener(this);
textShow=new JTextArea(10,30);
add(new JScrollPane(textShow));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{textshow.setBackground(Color.red);
}
}
原意是想设定一个按钮,然后点击一下,文本框就能变色的
import javax.swing.*;
import java.awt.event.*;
public class WindowActionEvent extends JFrame implements ActionListener
{
JTextField text;
JTextArea textShow;
JButton button;
public WindowActionEvent()
{
setLayout(new FlowLayout());
text=new JTextField(10);
add(text);
button=new JButton("确定");
add(button);
button.addActionListener(this);
textShow=new JTextArea(10,30);
add(new JScrollPane(textShow));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{textshow.setBackground(Color.red);
}
}
原意是想设定一个按钮,然后点击一下,文本框就能变色的