|
| ||||||||||
| Tags: code, java |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| JAVA code attached with explanation
Create an applet that has a JTextField for the user to enter the name of a color. If the color entered is not either red, white, blue, then your applet should throw an Exception and tell the user the color entered was not valid. Otherwise change the background color to the appropriate color. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Colors extends JApplet implements ActionListener //make the class { private GridLayout layout = new GridLayout(3, 1); JPanel panel02 = new JPanel(new FlowLayout()); //make panels JPanel panel03 = new JPanel(new FlowLayout()); JPanel panel04 = new JPanel(new FlowLayout()); Container con = getContentPane(); FlowLayout Lay = new FlowLayout(FlowLayout.CENTER); JLabel head = new JLabel("Please enter a color"); JTextField choice = new JTextField("",10); JButton enter = new JButton("Press After Typing"); JLabel error = new JLabel(""); JPanel pane = new JPanel() ; //make a new panel public void init() { con.setLayout(layout);//set the layout con.add(panel02); con.add(panel03); con.add(panel04); panel02.add(head); panel03.add(choice); panel03.add(enter); enter.addActionListener(this); panel04.add(error); } public static Color getColor(String cn) choice = cn; { try { if(cn == red) panel02.setBackground(Color.RED); else if(cn == blue) panel03.setBackground(Color.BLUE); else if(cn == white) panel04.setBackground(Color.WHITE); } catch(Exception ex) { error.setText("Wrong Color Choice"); } } } errors i get Colors.java:42: ';' expected public static Color getColor(String cn) ^ Colors.java:101: class, interface, or enum expected } ^ 2 errors |
|
#2
| |||
| |||
| Re: JAVA code attached with explanation
i fixed it thank you though |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "JAVA code attached with explanation" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help me to understand java code (calendar java code) ? | so0oma | Software Development | 2 | 09-01-2011 11:01 PM |
| help with java code | unikshegz | Software Development | 2 | 24-10-2010 02:47 PM |
| Use Java code in PHP | Gajendra1 | Software Development | 6 | 12-08-2010 10:18 AM |
| Need Explanation for java code | javainfo | Software Development | 2 | 10-12-2009 12:56 AM |
| need explanation on nested group code | vivekmohan | Software Development | 4 | 30-06-2009 03:09 PM |