java 不兼容的类型
importjava.awt.Graphics;importjava.applet.*;importjava.awt.*;importjava.awt.event.*;p...
import java.awt.Graphics;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class liwuqi extends Applet implements ItemListener
{
CheckboxGroup cg;
Checkbox red, yellow, green, blue;
Color co;
List lc;
String colorname[] = {"红色","黄色","绿色","蓝色","橙色","黑色","粉色"};
String colors[] = {Color.red,Color.yellow,Color.green,Color.blue,Color.orange,Color.black,Color.pink};
int a;
public void init()
{
cg = new CheckboxGroup();
co = Color.red;
red = new Checkbox("红色", cg, true);
red.addItemListener(this);
add(red);
yellow = new Checkbox("黄色", cg, false);
yellow.addItemListener(this);
add(yellow);
green = new Checkbox("绿色", cg, false);
green.addItemListener(this);
add(green);
blue = new Checkbox("蓝色", cg, false);
blue.addItemListener(this);
add(blue);
lc = new List(5,false);
lc.addItemListener(this);
for(int i = 0; i<colorname.length; i++)
{
lc.add(colorname[i]);
}
add(lc);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == red) co = Color.red;
if(e.getSource() == yellow) co = Color.yellow;
if(e.getSource() == green) co = Color.green;
if(e.getSource() == blue) co = Color.blue;
showStatus(lc.getSelectedItem() + ":顺序号" + lc.getSelectedIndex());
a = lc.getSelectedIndex();
repaint();
}
public void paint(Graphics g)
{
g.setColor(co);
g.fillRect(50, 80, 50, 50);
g.setColor(colors[a]);
g.fillOval(270, 100, 50, 50);
}
}
在教材上抄了一个程序,有错误,请各位大侠帮忙调一下。我都弄了好久了。 展开
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class liwuqi extends Applet implements ItemListener
{
CheckboxGroup cg;
Checkbox red, yellow, green, blue;
Color co;
List lc;
String colorname[] = {"红色","黄色","绿色","蓝色","橙色","黑色","粉色"};
String colors[] = {Color.red,Color.yellow,Color.green,Color.blue,Color.orange,Color.black,Color.pink};
int a;
public void init()
{
cg = new CheckboxGroup();
co = Color.red;
red = new Checkbox("红色", cg, true);
red.addItemListener(this);
add(red);
yellow = new Checkbox("黄色", cg, false);
yellow.addItemListener(this);
add(yellow);
green = new Checkbox("绿色", cg, false);
green.addItemListener(this);
add(green);
blue = new Checkbox("蓝色", cg, false);
blue.addItemListener(this);
add(blue);
lc = new List(5,false);
lc.addItemListener(this);
for(int i = 0; i<colorname.length; i++)
{
lc.add(colorname[i]);
}
add(lc);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == red) co = Color.red;
if(e.getSource() == yellow) co = Color.yellow;
if(e.getSource() == green) co = Color.green;
if(e.getSource() == blue) co = Color.blue;
showStatus(lc.getSelectedItem() + ":顺序号" + lc.getSelectedIndex());
a = lc.getSelectedIndex();
repaint();
}
public void paint(Graphics g)
{
g.setColor(co);
g.fillRect(50, 80, 50, 50);
g.setColor(colors[a]);
g.fillOval(270, 100, 50, 50);
}
}
在教材上抄了一个程序,有错误,请各位大侠帮忙调一下。我都弄了好久了。 展开
4个回答
展开全部
import java.awt.Graphics;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class liwuqi extends Applet implements ItemListener
{
CheckboxGroup cg;
Checkbox red, yellow, green, blue;
Color co;
List lc;
String colorname[] = {"红色","黄色","绿色","蓝色","橙色","黑色","粉色"};
Color colors[] = {Color.red,Color.yellow,Color.green,Color.blue,Color.orange,Color.black,Color.pink};
int a;
public void init()
{
cg = new CheckboxGroup();
co = Color.red;
red = new Checkbox("红色", cg, true);
red.addItemListener(this);
add(red);
yellow = new Checkbox("黄色", cg, false);
yellow.addItemListener(this);
add(yellow);
green = new Checkbox("绿色", cg, false);
green.addItemListener(this);
add(green);
blue = new Checkbox("蓝色", cg, false);
blue.addItemListener(this);
add(blue);
lc = new List(5,false);
lc.addItemListener(this);
for(int i = 0; i<colorname.length; i++)
{
lc.add(colorname[i]);
}
add(lc);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == red) co = Color.red;
if(e.getSource() == yellow) co = Color.yellow;
if(e.getSource() == green) co = Color.green;
if(e.getSource() == blue) co = Color.blue;
showStatus(lc.getSelectedItem() + ":顺序号" + lc.getSelectedIndex());
a = lc.getSelectedIndex();
repaint();
}
public void paint(Graphics g)
{
g.setColor(co);
g.fillRect(50, 80, 50, 50);
g.setColor(colors[]);
g.fillOval(270, 100, 50, 50);
}
}
颜色的地方错了一个小地方
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class liwuqi extends Applet implements ItemListener
{
CheckboxGroup cg;
Checkbox red, yellow, green, blue;
Color co;
List lc;
String colorname[] = {"红色","黄色","绿色","蓝色","橙色","黑色","粉色"};
Color colors[] = {Color.red,Color.yellow,Color.green,Color.blue,Color.orange,Color.black,Color.pink};
int a;
public void init()
{
cg = new CheckboxGroup();
co = Color.red;
red = new Checkbox("红色", cg, true);
red.addItemListener(this);
add(red);
yellow = new Checkbox("黄色", cg, false);
yellow.addItemListener(this);
add(yellow);
green = new Checkbox("绿色", cg, false);
green.addItemListener(this);
add(green);
blue = new Checkbox("蓝色", cg, false);
blue.addItemListener(this);
add(blue);
lc = new List(5,false);
lc.addItemListener(this);
for(int i = 0; i<colorname.length; i++)
{
lc.add(colorname[i]);
}
add(lc);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == red) co = Color.red;
if(e.getSource() == yellow) co = Color.yellow;
if(e.getSource() == green) co = Color.green;
if(e.getSource() == blue) co = Color.blue;
showStatus(lc.getSelectedItem() + ":顺序号" + lc.getSelectedIndex());
a = lc.getSelectedIndex();
repaint();
}
public void paint(Graphics g)
{
g.setColor(co);
g.fillRect(50, 80, 50, 50);
g.setColor(colors[]);
g.fillOval(270, 100, 50, 50);
}
}
颜色的地方错了一个小地方
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java.awt.Color
Color.red,Color.yellow,Color.green,Color.blue,Color.orange,Color.black,Color.pink
这些返回的全部都是Color型的对象 你吧Color型的对象放到String的数组里...所以 当然不兼容了
Color.red,Color.yellow,Color.green,Color.blue,Color.orange,Color.black,Color.pink
这些返回的全部都是Color型的对象 你吧Color型的对象放到String的数组里...所以 当然不兼容了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String colors[]
改成
Color colors[]
改成
Color colors[]
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询