这个程序如何才能做到文本框变色呢。
importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;publicclassWindowActionEv...
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class WindowActionEvent extends JFrame{
JTextField text;
ActionListener listener;
public WindowActionEvent(){
setLayout(new FlowLayout());
text=new JTextField(10);
add(text);
listener=new ReaderListen();
text.addActionListener(listener);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class ReaderListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
text.setBackground(Color.red);
}
} 展开
import javax.swing.*;
import java.awt.event.*;
public class WindowActionEvent extends JFrame{
JTextField text;
ActionListener listener;
public WindowActionEvent(){
setLayout(new FlowLayout());
text=new JTextField(10);
add(text);
listener=new ReaderListen();
text.addActionListener(listener);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
public class ReaderListen implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
text.setBackground(Color.red);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询