2 Replies - 4104 Views - Last Post: 06 April 2013 - 07:59 PM Rate Topic: -----

#1 Csoto282   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-April 13

Java error, Illegal Start of Statement

Posted 06 April 2013 - 09:01 AM

I was learning how to make a paint program, when I code I'm the type of person who always get errors, even in school I get tons of errors. I received an error saying illagal start of statement and and that I have semi-colons in wrong places but everything looks fine, I don't see anything wrong with my constructors. T

This is a basic paint program, with about 55 errors regarding ';' expected and illegal start statement.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class paint {
    public static void main(String[] args) {
    	//Imagine for the colors
    	Icon iconB = new Icon("blue.gif");
    	Icon iconM = new Icon("Magneta.gif");
    	Icon iconR = new Icon("red.gif");
    	Icon iconBl = new Icon("black.gif");
    	Icon iconG = new Icon("green.gif");
    	// Make the Frame
    	JFrame frame = new JFrame("Wookie SHOP"); //My title for the program
    	Container content = frame.getContainer();
    	content.setLayout(new BorderLayout()); // Sets the layout
    	final PadDraw drawPad = new PadDraw(); // Creates a new padDraw which is pretty much the new paint program
    	content.add(drawPad,BorderLayout.CENTER); // Puts the pad in the center
    	// Make the panel
    	JPanel panel = new JPanel(); // Makes the panel 
    	panel.setPreferredSize(new Demension(32,68));
    	panel.MinimalSize(new Demension(32,68));
    	panel.MaximumSize(new Demension(32,68));
    	// The button
    	JButton clearBtn = new JButton("Clear"); // Makes the clear button sets the text as clear
    	clearBtn.addActionListener(new ActionListener());
    	public void actionPerformed(ActionEvent e);
    	//Red Button
    	JButton redBtn = new JButton(iconR);
    	redBtn.addActionListener(new ActionListener());
    	public void actionPerformed(ActionEvent e);
    		// Black Button
    		JButton blackBtn = new JButton(iconBl);
    		blackBtn.addActionListener(new ActionListener());
    		public void actionPerformed(ActionEvent e);
    	 // Megneta buttom
    	 JButton MagnetaBtn = new JButton(iconM);
    	 MagnetaBtn.addActionListener(new ActionListener());
    	 public void actionPerformed(ActionEvent e);
    	 // blue button
    	 JButton blueBtn = new JButton(iconB);
    	 blueBtn.addActionListener(new ActionListener());
    	 public void actionPerformed(ActionEvent e);
    	//Green Button
    	JButton greenBtn = new JButton(iconG);
    	 greenBtn.addActionListener(new ActionListener());
    	 public void actionPerformed(ActionEvent e);
    	// Set size
    	redBtn.setPreferredSize(new Dimension(16,16));
    	blackBtn.setPreferredSize(new Dimension(16,16));
    	MagnetaBtn.setPreferredSize(new Dimension(16,16));
    	blueBtn.setPreferredSize(new Dimension(16,16));
    	greenBtn.setPreferredSize(new Dimension(16,16))
    		// Add buttons to the panel
    		// Set panel to the left
    		content.add(panel, BorderLayout.WEST);
    		// Set size of the frame 
    		//Make it where we close the frame
    		private class PadDraw extends JComponent
    			Image image; // The image we draw on
    			Graphics2D graphics2d; // What we'll use to draw
    			int currentX  , currentY  , oldX , oldY; // Going to hold our coordinates
    			// Need cOnstructor To create what we got above ^^/>/>
    			public PadDraw()
    				addMouseListener(new MouseAdapter()){
    					public void mousePressed(MouseEvent e){
    						oldX = e.getX();
    						oldY = e.getY();
    					}// End of constructor
    				} // if the mouse is pressed it sets oldX and old Y
    				// Coordinates as the Mouse X and Y
    				addMouseMotionListener(new MouseMotionAdapter()){
    					public void MouseDragged(MouseEvent e){
    						currentX = e.getX();
    						currentY = e.getY();
    						oldX = currentX;
    						oldY = currentY;
    					//while the mouse is dragged it sets current x and currentY as the mouse x and y.
    					//Then then it draws a line at it coordinates
    					// It repaints it and sets oldX and oldY as currentX and currentY
    				}// End of constructor MouseMotionListener
    				public void paintComponent(Graphics g){
    						image = createImage(getSize().width , getHeight().height);
    						graphics2D = (Graphics2D) image.getGraphics();
    						graphics2D.setRenderHints(RenderingHints.KEY_ANTIALIASING , RenderingHints.VALUE_ANTIALIAS_ON);
    					//If the painting bit doesn't hold anything then it creates an image the size of the window
    					//sets the value of the graphics,sets the rendering, runs the clearing method and then it 
    					// draws the image
    				}// End of Paint Component
    				public void clear(){
    				// this is the clear, it sets the color to white , then it fills the window with white
    				// then sets the color back to black
    				public void red(){
    				public void magneta(){
    				public void blue(){
    				public void green(){
    				return	graphics2D.setPaint(Color.green);

Is This A Good Question/Topic? 0
  • +

Replies To: Java error, Illegal Start of Statement

#2 GregBrannon   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: Java error, Illegal Start of Statement

Posted 06 April 2013 - 09:05 AM

Many (if not all) of the anonymous inner class constructs are wrong. Focus on those.
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java error, Illegal Start of Statement

Posted 06 April 2013 - 07:59 PM

I hate those :gun_bandana:

1) they make constructors long for nothings
2) they mix code only executed once and code executed at each action performed
3) they do not centralize in one place what is event drivern

but your choice
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1