RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java更改代码颜色 java自定义颜色

请问各位高手,在java中,如何实现输入RGB值改变颜色?

import java.awt.BorderLayout;

创新互联-专业网站定制、快速模板网站建设、高性价比介休网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式介休网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖介休地区。费用合理售后完善,10余年实体公司更值得信赖。

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的写代码的面板的背景色怎么改?白色太刺眼

不知道你说的是不是eclipse的编辑区域的背景,我估且认为是吧。

打开菜单Windows-Preferences在弹出的界面中,选择General-Editor-Text Editors,在右边的界面中的Appearance color options中选择Background color,取消勾选右边的System Default,然后就可以选择自己想要的颜色了。

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更改代码颜色 java自定义颜色
分享链接:http://sczitong.cn/article/ddjcjde.html