关于java编程 getColorModel()语句的问题,求大神解答 50
这是一段显示鼠标指针处像素RGB的程序,前面的没有问题,x,y是鼠标坐标,但是rgb输出一直不正确,求大神解答publicvoidgetPixel(intx,inty){...
这是一段显示鼠标指针处像素RGB的程序,前面的没有问题,x,y是鼠标坐标,但是rgb输出一直不正确,求大神解答
public void getPixel(int x,int y){
ColorModel cm = this.getColorModel();
int rgb = cm.getRGB(x*y);
System.out.println(rgb);
int a= (rgb&0x00ff0000)>>24;
int red = (rgb&0x00ff0000)>>16 ;
int green = (rgb&0x0000ff00)>>8 ;
int blue = (rgb&0x000000ff) ;
System.out.println( "("+red+","+green+ ","+blue+ ")"+"\nalpha为"+a);
} 展开
public void getPixel(int x,int y){
ColorModel cm = this.getColorModel();
int rgb = cm.getRGB(x*y);
System.out.println(rgb);
int a= (rgb&0x00ff0000)>>24;
int red = (rgb&0x00ff0000)>>16 ;
int green = (rgb&0x0000ff00)>>8 ;
int blue = (rgb&0x000000ff) ;
System.out.println( "("+red+","+green+ ","+blue+ ")"+"\nalpha为"+a);
} 展开
1个回答
展开全部
public class Car {
private int speed = 0; // 速度
private boolean on = false; // 是否启动?
private double weight = 1.2; // 汽车重量
private String color = "blue";// 颜色
public static void main(String[] args) {
// 4、①用无参构造方法创建默认汽车
Car car = new Car();
//5、创建两个car对象
Car car1 = new Car() ;
car1.setSpeed(120); //km/h
car1.setWeight(1.2D);
car1.setColor("black");
car1.setOn(true);
System.out.println(car1.toString());
Car car2 = new Car() ;
car2.setSpeed(0); //km/h
car2.setWeight(1.2D);
car2.setColor("red");
car2.setOn(false);
System.out.println(car2.toString());
}
//4、②编写设置和存取这些数据域的方法
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
//4、③toString()方法描述汽车的字符串
@Override
public String toString() {
if(on) {
return "当前行驶速度 : " + speed + "km/h, 颜色 : " + color + ", 重量 : " + weight + "吨。";
}else {
return "car is off, 颜色 : " + color + ", 重量 : " + weight + "吨。";
}
}
}
private int speed = 0; // 速度
private boolean on = false; // 是否启动?
private double weight = 1.2; // 汽车重量
private String color = "blue";// 颜色
public static void main(String[] args) {
// 4、①用无参构造方法创建默认汽车
Car car = new Car();
//5、创建两个car对象
Car car1 = new Car() ;
car1.setSpeed(120); //km/h
car1.setWeight(1.2D);
car1.setColor("black");
car1.setOn(true);
System.out.println(car1.toString());
Car car2 = new Car() ;
car2.setSpeed(0); //km/h
car2.setWeight(1.2D);
car2.setColor("red");
car2.setOn(false);
System.out.println(car2.toString());
}
//4、②编写设置和存取这些数据域的方法
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public boolean isOn() {
return on;
}
public void setOn(boolean on) {
this.on = on;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
//4、③toString()方法描述汽车的字符串
@Override
public String toString() {
if(on) {
return "当前行驶速度 : " + speed + "km/h, 颜色 : " + color + ", 重量 : " + weight + "吨。";
}else {
return "car is off, 颜色 : " + color + ", 重量 : " + weight + "吨。";
}
}
}
追问
所答非所问
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |