网站建设资讯

NEWS

网站建设资讯

java怎么换颜色代码 java代码设置颜色

java改变按钮颜色

为yellow、blue、red3个按钮添加actionlistener,当按钮点击时执行setBackground(backgroundColor),同时执行 按钮.setBackground(backgroundColor)即可,比如:

10年积累的成都网站制作、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计制作后付款的网站建设流程,更有大竹免费网站建设让你可以放心的选择与我们合作。

JButton btnYellow = null;

JButton btnBlue = null;

JButton btnRed = null;

btnYellow.setActionCommand("yellow");

btnBlue.setActionCommand("blue");

btnRed.setActionCommand("red");

public void actionPerformed(ActionEvent e) {

String command = event.getActionCommand();

if( "yellow".equals(command) ){

setBackground(Color.yellow);

btnYellow.setBackground(Color.yellow);

}else if( "blue".equals(command) ){

setBackground(Color.blue);

btnBlue.setBackground(Color.blue);

}else if( "red".equals(command) ){

setBackground(Color.red);

btnRed.setBackground(Color.red);

}

}

写出了部分代码

爱心代码编程java怎样加颜色

1、首先打开java编译软件,引入爱心代码编程。

2、其次打开图面编译,选择编辑颜色。

3、最后在该代码编程中输入需要添加的颜色即可。

java金褐中颜色代码怎么加

1、首先进入javaAPP。

2、其次选择金褐中颜色代码。

3、最后选择想要添加的位置进行添加即可。

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颜色代码

setTextColor(0xFF0000FF);

//0xFF0000FF是int类型的数据,分组一下0x|FF|0000FF,0x是代表颜色整 数的标记,ff是表示透明度,0000FF表示颜色,注意:这里0xFF0000FF必须是8个的颜色表示,不接受0000FF这种6个的颜色表示。

setTextColor(Color.rgb(255, 255, 255));

setTextColor(Color.parseColor("#FFFFFF"));

//还有就是使用资源文件进行设置

setTextColor(this.getResources().getColor(R.color.blue));

//通过获得资源文件进行设置。根据不同的情况R.color.blue也可以是R.string.blue或者

//另外还可以使用系统自带的颜色类

setTextColor(android.graphics.Color.BLUE);

java GUI 按下回车键换背景颜色代码

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class KeyCharEx extends JFrame {

JLabel la = new JLabel("Enter键换背景颜色");

KeyCharEx() {

super("请按Enter键");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLayout(new FlowLayout());

this.add(la);

this.addKeyListener(new MyKeyListener());// 整个界面添加键盘敲击事件

setSize(250, 150);

setVisible(true);

}

class MyKeyListener extends KeyAdapter {

public void keyTyped(KeyEvent e) {// 应该是这个方法 keyTyped 键盘按下,然后释放

super.keyTyped(e);

int r = (int) (Math.random() * 256);

int g = (int) (Math.random() * 256);

int b = (int) (Math.random() * 256);

switch (e.getKeyChar()) {

case '\n':

la.setText("r=" + r + ",g=" + g + ",b=" + b);

getContentPane().setBackground(new Color(r, g, b));

break;

case 'q':

System.exit(0);

}

}

}

public static void main(String[] args) {

new KeyCharEx();

}

}


名称栏目:java怎么换颜色代码 java代码设置颜色
分享链接:http://cdweb.net/article/hpdics.html