我在Frame中添加一个TextField文本框,现在我想改变我输入文本的颜色,就是点一下鼠标选那个颜色
就变成那种颜色,应该调用什么方法,处理什么事件?希望大家指点.谢谢!
就变成那种颜色,应该调用什么方法,处理什么事件?希望大家指点.谢谢!
解决方案 »
- 菜鸟救助老鸟!将下段C#代码翻译成java代码
- java 基础问题~~~
- 关于CSDN博客API的使用问题,提交metaWeblog.newPost出错
- SWING日历面版控件(WINDOWS标准样式),可嵌入各种面版中,跟据大小自动调节
- 小妹首次求教:下面的功能如何实现(别笑我)
- jsp实现文件批量下载问题,请高手赐教
- 评价做图书管理系统用c/s结构还是b/s结构
- 关于override的一个问题。
- 问个让人郁闷的问题,请给出答案和运行的顺序^^
- java访问nfs服务
- java1.5中,使用import语句,什么时候需要加入 static?
- 初学者的问题,和以前的有点大同小异,但就是想问问.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;public class ButtonTest
{ public static void main(String[] args)
{
ButtonFrame frame = new ButtonFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true); }}class ButtonFrame extends JFrame
{
public ButtonFrame()
{
setTitle("ButtonTest");
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); ButtonPanel panel = new ButtonPanel();
add(panel);
} private static final int DEFAULT_WIDTH = 300; private static final int DEFAULT_HEIGHT = 200;
}class ButtonPanel extends JPanel
{
JTextField text = null; public ButtonPanel()
{
JButton yellowButton = new JButton("<html><b>Yellow</b></html>");
JButton blueButton = new JButton("Blue");
JButton redButton = new JButton("Red");
text = new JTextField(8); yellowButton.addActionListener(new ColorAction(Color.YELLOW));
blueButton.addActionListener(new ColorAction(Color.BLUE));
redButton.addActionListener(new ColorAction(Color.RED)); add(yellowButton);
add(blueButton);
add(redButton);
add(text);
} private class ColorAction implements ActionListener
{
public ColorAction(Color c)
{
this.backgroundColor = c;
} public void actionPerformed(ActionEvent event)
{
ButtonPanel.this.text.setBackground(backgroundColor);
;
} private Color backgroundColor;
}
}
删掉好了