|
-
September 19th, 2011, 12:44 PM
#1
error code help
Hello everybody.
I have met a problem ,the following java code can't be compiled successfully in one of my computer but can be succeed in another one.Does anyone could tell me what is the problem?
I list the Code and Error message as below:
thank you in advance!
Code:
//////////////////////////////////////Code://///////////////////////////////////////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Win extends JFrame implements ItemListener
{ JComboBox list;
JTextArea text;
Win()
{ list=new JComboBox();
text=new JTextArea();
Button b=new Button();
b.setBackground(Color.yellow);
text.setForeground(new Color(12,250,34));
list.setForeground(Color.blue);
list.setBackground(Color.cyan);
GraphicsEnvironment ge=
GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontName[]=ge.getAvailableFontFamilyNames();
for(int i=0;i<fontName.length;i++)
{ list.addItem(fontName[i]);
}
add(list,BorderLayout.NORTH);
add(new JScrollPane(text),BorderLayout.CENTER);
list.addItemListener(this);
setVisible(true);
setBounds(100,120,300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
validate();
}
public void itemStateChanged(ItemEvent e)
{ String name=(String)list.getSelectedItem();
Font f=new Font(name,Font.BOLD,32);
text.setFont(f);
text.setText("\n2008bj");
}
}
public class Example8_18
{ public static void main(String args[])
{ Win win=new Win();
}
}
///////////////////////////////////Error Message:////////////////////////////////////////////
Example8_18.java:11: setBackground(java.awt.Color) in java.awt.Component cannot
be applied to (Color)
b.setBackground(Color.yellow);
^
Example8_18.java:12: enum types may not be instantiated
text.setForeground(new Color(12,250,34));
^
Example8_18.java:13: cannot find symbol
symbol : method setForeground(Color)
location: class javax.swing.JComboBox
list.setForeground(Color.blue);
^
Example8_18.java:14: cannot find symbol
symbol : variable cyan
location: class Color
list.setBackground(Color.cyan);
^
4 errors
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|