「java程序中颜色怎么改」java中颜色怎么定义
本篇文章给大家谈谈java程序中颜色怎么改,以及java中颜色怎么定义对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、JAVA中怎么改变字体颜色?
- 2、java 编程 背景颜色的改变
- 3、如何改变java按钮中的颜色?
- 4、请问java中怎样设置字体的颜色?
- 5、java异常信息字体颜色能改吗
- 6、请问各位高手,在java中,如何实现输入RGB值改变颜色?
JAVA中怎么改变字体颜色?
字体大小及颜色
a:Java代码区域的字体大小和颜色:
window -- Preferences -- General -- Appearance -- Colors And Fonts -- Java修改 -- Java Edit Text Font
b:控制台
window -- Preferences -- General -- Appearance -- Colors And Fonts -- Debug -- Console font
c:其他文件
window -- Preferences -- General -- Appearance -- Colors And Fonts -- Basic -- Text Font
java 编程 背景颜色的改变
**************************************************************
新建一个类ChangeColor.java,代码如下:
**************************************************************
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
/**
* @author Godwin
* @version 2010-05-16
*/
public class ChangeColor extends JFrame implements MouseMotionListener {
public ChangeColor() {
this.setTitle("Change Color");
this.setBounds(300, 200, 400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.getContentPane().setBackground(Color.GREEN);
this.addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent e) {
if (e.getX() (this.getWidth() / 2)) {
this.getContentPane().setBackground(Color.RED);
} else {
this.getContentPane().setBackground(Color.BLUE);
}
}
public void mouseDragged(MouseEvent e) {
}
public static void main(String[] args) {
new ChangeColor();
}
}
**************************************************************
运行结果如下:
**************************************************************
如何改变java按钮中的颜色?
setForeground() 设置前景/字体颜色
setBackground() 设置背景颜色
具体实现:(假设按钮名称为:button)
设置红字:
button.setForeground(Color.red);
设置黑色背影:
button.setBackground(Color.black);
请问java中怎样设置字体的颜色?
下拉框和textfield,textarea这些控件都有setforeground方法,这个函数是设置前景色的,设置为红色就行了.
例如:textfield
txt=new
textfield("请输入姓名");
txt.setforeground(color.red);
java异常信息字体颜色能改吗
java异常信息字体颜色能改。直接用color属性就可以改了,在项目里面也用到很多字体图标,直接修改color属性颜色就可以修改字体颜色了。
请问各位高手,在java中,如何实现输入RGB值改变颜色?
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class RGB extends JFrame implements ActionListener{
JTextField t1,t2,t3;
JLabel b1,b2,b3;
JButton jb;
JPanel jp;
public RGB(){
super("RGB");
jp=new JPanel();
b1=new JLabel("R");
b2=new JLabel("G");
b3=new JLabel("B");
t1=new JTextField(3);
t2=new JTextField(3);
t3=new JTextField(3);
jb=new JButton("确定");
jb.addActionListener(this);
jp.add(b1);
jp.add(t1);
jp.add(b2);
jp.add(t2);
jp.add(b3);
jp.add(t3);
jp.add(jb);
jp.setLayout(new FlowLayout());
add(jp,BorderLayout.CENTER);
setSize(200,200);
setResizable(false);
setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource().getClass().getSimpleName().equals("JButton")){
int r=Integer.parseInt(t1.getText());
int g=Integer.parseInt(t2.getText());
int b=Integer.parseInt(t3.getText());
if(r=0 r=255 g=0 g=255 b=0 b=255){
Color c=new Color(r,g,b);
jp.setBackground(c);
}else{
System.out.println("请输入(0-255)的整数!");
}
}
}
public static void main(String[] args) {
new RGB();
}
}
java程序中颜色怎么改的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java中颜色怎么定义、java程序中颜色怎么改的信息别忘了在本站进行查找喔。
发布于:2022-12-11,除非注明,否则均为
原创文章,转载请注明出处。