this is my code. I have no clue what could be wrong with it. The error that keeps coming up is: class, interface, or enum expected. The five errors it pointed out are the 'v' in public void actionPerformed at the bottom of the code, the 'g' in the green = Integer.parseInt....., the 'b' in the blue = Integer.parseInt..... the 'r' in the repaint().. and '}' at the very end of the code... anyone can help?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class UpdatedColorApplet extends JApplet implements ActionListener {
private JTextField txtRed = new JTextField("255", 3);
private JTextField txtGreen = new JTextField("255", 3);
private JTextField txtBlue = new JTextField("255", 3);
private JButton cmdEnter = new JButton("Enter");
private int red=255;
private int green=255;
private int blue=255;
/**
* The entry point for the applet.
*/
public UpdatedColorApplet(){
// get contentPane & set layout manager
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
// text components & labels
cp.add(new JLabel("CPT 237 - Java - Color Class RGB Component Demonistration Applet"));
cp.add(new JLabel("Red"));
cp.add(txtRed);
cp.add(new JLabel("Green"));
cp.add(txtGreen);
cp.add(new JLabel("Blue"));
cp.add(txtBlue);
cp.add(new NewLabel());
// add button and set up handler
cp.add(cmdEnter);
cmdEnter.addActionListener(this);
}
public static void main(String[] args) {
UpdatedColorApplet frame = new UpdatedColorApplet();
frame.setSize(250, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class NewLabel extends JLabel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// draw the large rectangle
g.setColor(new Color(red, green, blue));
g.fillRect(100, 100, 200, 150);
// draw the red component rectangle
g.setColor(new Color(red, 0, 0));
g.fillRect(120, 120, 40, 100);
// draw the green component rectangle
g.setColor(new Color(0, green, 0));
g.fillRect(180, 120, 40, 100);
// draw the blue component rectangle
g.setColor(new Color(0, 0, blue));
g.fillRect(240, 120, 40, 100);
}
}
public void actionPerformed(ActionEvent e) {
// get color components
red = Integer.parseInt(txtRed.getText());
green = Integer.parseInt(txtGreen.getText());
blue = Integer.parseInt(txtBlue.getText());
// repaint the applet
repaint();
}