GUI Implementation Errors

Program created: photo manipulation (via pixels) Desired: GUI

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 4881 Views - Last Post: 19 December 2010 - 12:19 AM Rate Topic: -----

#16 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 08:58 PM

I think we're getting into simpler errors now.

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class photo implements ActionListener
{
	class GUI
	{
		public JButton bw;
		public JButton neg;
		public JButton sepia;
		public JButton original;
		public Picture photo;
		public String file;
		public Pixel[] array;
	}
	public static void main(String[] args)
	{
		photo = new Picture();
		file = "peter.jpg";
		array = photo.getPixels();
		Scanner scan = new Scanner(System.in);
		photo.load(file);
		
		JFrame gui = new JFrame("Photo Manipulation");
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel buttons = new JPanel();
		buttons.setLayout(new GridLayout(2,2));
		JButton bw = new JButton();
		bw.setText("Black and White");
		buttons.add(bw);
		JButton neg = new JButton();
		neg.setText("Negative");
		buttons.add(neg);
		JButton sepia = new JButton();
		sepia.setText("Sepia");
		buttons.add(sepia);
		JButton original = new JButton();
		original.setText("Original");
		buttons.add(original);
		
		gui.getContentPane().add(buttons);
		gui.pack();
		gui.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		final GUI object = new GUI();
		if (event.getSource() == object.bw)
		{	
			object.bw.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(object.file);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						int w = (r+b+g)/3;
						temparray[i].setRed(w);
						temparray[i].setGreen(w);
						temparray[i].setBlue(w);
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == object.neg)
		{
			object.neg.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(object.file);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == object.sepia)
		{
			object.sepia.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(object.file);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == object.original)
		{
			object.photo.show();
		}
	}
}



C:\Users\Jordan\JavaDocs\Gooey>javac photo.java
photo.java:19: cannot find symbol
symbol : variable photo
location: class photo
photo = new Picture();
^
photo.java:20: cannot find symbol
symbol : variable file
location: class photo
file = "peter.jpg";
^
photo.java:21: cannot find symbol
symbol : variable array
location: class photo
array = photo.getPixels();
^
photo.java:21: cannot find symbol
symbol : method getPixels()
location: class photo
array = photo.getPixels();
^
photo.java:23: cannot find symbol
symbol : variable file
location: class photo
photo.load(file);
^
5 errors

I'm sure this has to do with my GUI class, but when I put GUI object = new GUI(); it gave me another static error
Was This Post Helpful? 0
  • +
  • -

#17 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:15 PM

Why do you have a GUI class inside of a photo class and then have main() inside of it all? K.I.S.S. is the best principle you can use. Slim everything down and get rid of what you don't NEED and what is not essential to the structure of the program.

In other words, make your code less complex.
Was This Post Helpful? 0
  • +
  • -

#18 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:18 PM

View PostDogstopper, on 17 December 2010 - 08:15 PM, said:

Why do you have a GUI class inside of a photo class and then have main() inside of it all? K.I.S.S. is the best principle you can use. Slim everything down and get rid of what you don't NEED and what is not essential to the structure of the program.

In other words, make your code less complex.


I'm afraid I was never taught the K.I.S.S. principal. I'm starting to doubt my university professors skills..

But, I put all those public variables into a class for the purpose that I can access them anywhere (because when I passed in classes as parameters into the actionlistener class, it blew up on me.
Was This Post Helpful? 0
  • +
  • -

#19 pbl   User is offline

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

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

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:21 PM

photo = new Picture();

your variable photo is not defined you need something like

Picture photo = new Picture();

by the way very confusing to have a variable photo in a class photo
respect commonly accepted convention to start your class name by a Captital letter
so
class Photo implements ActionListener {
....
    Picture photo = new Picture();


actually not a very good idea to have a variable named photo in a class Photo that is not a Photo ocbject better to
Picture picture = new Picture();

file = "peter.jpg";

same error file is not defined you need
String file = "peter.jpg";

again confusing is file a File or a String use
String filename = "peter.jpg";
or
File file = new File("peter.jpg");

same thing for array not defined

Now you mat thing that you have defined all these variable in the instance variables of the class
You cannot access them from main() which is static. You need to access them through a photo object

public static void main(String[] args) {
   photo p = new photo();
   p.photo = new Picture();
   p.file = "peter.jpg";


but this is an horrible practice

You main() method should have only just a few lines just to start the application
the rest should happen in the class

class Photo implements ActionListener {

    Picture picture;
    String filename;
    ... rest of your instance variable here

    // constructor that receives the .jpg as parameter
    Photo(String filename) {
        this.filename = filename;
        picture = new Picture();
        ....
        rest of your Photo building code here
    }

    public static void main(String[] arg) {
      Photo phot = new Photo("peter.jpg");
    }    // <---- that's it


Was This Post Helpful? 2
  • +
  • -

#20 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:36 PM

That made perfect sense! I was able to make the GUI pop up, and everything looks smooth.

One problem.

When I click the buttons, nothing happens. Is there something wrong with the JFrame gui (pack,adding buttons etc) or is the actionlistener class failing me horribly?

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class Photo implements ActionListener 
{
    Picture picture;
    String filename;
	Pixel[] array;
	public JButton neg;
	public JButton original;
	public JButton sepia;
	public JButton bw;
    Photo(String filename) 
	{
		this.picture = new Picture();
        this.filename = filename;
		this.array = picture.getPixels();
		picture.load(filename);
    }
    public static void main(String[] arg) 
	{
		Photo phot = new Photo("peter.jpg");
		
		JFrame gui = new JFrame("Photo Manipulation");
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel buttons = new JPanel();
		buttons.setLayout(new GridLayout(2,2));
		JButton bw = new JButton();
		bw.setText("Black and White");
		buttons.add(bw);
		JButton neg = new JButton();
		neg.setText("Negative");
		buttons.add(neg);
		JButton sepia = new JButton();
		sepia.setText("Sepia");
		buttons.add(sepia);
		JButton original = new JButton();
		original.setText("Original");
		buttons.add(original);
		
		gui.getContentPane().add(buttons);
		gui.pack();
		gui.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == bw)
		{	
			bw.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						int w = (r+b+g)/3;
						temparray[i].setRed(w);
						temparray[i].setGreen(w);
						temparray[i].setBlue(w);
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == neg)
		{
			neg.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == sepia)
		{
			sepia.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == original)
		{
			picture.show();
		}
	}
}



As you will see, the GUI pops up, but no functionality.
Was This Post Helpful? 0
  • +
  • -

#21 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12335
  • View blog
  • Posts: 45,442
  • Joined: 27-December 08

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:38 PM

You need to add the ActionListener to the JButtons. Also, better practice to initialize your GUI in the constructor rather than the main() method.
Was This Post Helpful? 0
  • +
  • -

#22 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:44 PM

The buttons were given the actionlistener though, lines 51, 74, and 99
Was This Post Helpful? 0
  • +
  • -

#23 mufasa   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 44
  • Joined: 12-February 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:50 PM

you should be adding the action listeners for the buttons when you create the buttons
Was This Post Helpful? 0
  • +
  • -

#24 pbl   User is offline

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

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

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:52 PM

View PostRUFerret, on 17 December 2010 - 10:36 PM, said:

That made perfect sense! I was able to make the GUI pop up, and everything looks smooth.

One problem.

When I click the buttons, nothing happens. Is there something wrong with the JFrame gui (pack,adding buttons etc) or is the actionlistener class failing me horribly?


Same problem... I told you your main() method should have only one line !!!

public class Photo implements ActionListener 
{
    Picture picture;
    String filename;
	Pixel[] array;
	public JButton neg;
	public JButton original;
	public JButton sepia;
	public JButton bw;

... your other buttons go here
    Photo(String filename) 
	{
		this.picture = new Picture();
        this.filename = filename;
		this.array = picture.getPixels();
		picture.load(filename);
    }
    public static void main(String[] arg) 
	{
		Photo phot = new Photo("peter.jpg");


// all the rest should go into your photo constructor		
		JFrame gui = new JFrame("Photo Manipulation");
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel buttons = new JPanel();
		buttons.setLayout(new GridLayout(2,2));
		JButton bw = new JButton();   <--- this button bw will just exist the time your
		bw.setText("Black and White");  <--- main method run
		buttons.add(bw);
		JButton neg = new JButton();
		neg.setText("Negative");
		buttons.add(neg);
		JButton sepia = new JButton();
		sepia.setText("Sepia");
		buttons.add(sepia);
		JButton original = new JButton();
		original.setText("Original");
		buttons.add(original);
		
		gui.getContentPane().add(buttons);
		gui.pack();
		gui.setVisible(true);
	}     <----- method main finishes... you cannot access neg, sepia, original anymore
	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == bw)   <---- this reference the JButton bw declared
		{	                      <--- in your instance variable NOT the one in main()
                                              <---- that you cannot access anymore
			bw.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						int w = (r+b+g)/3;
						temparray[i].setRed(w);
						temparray[i].setGreen(w);
						temparray[i].setBlue(w);
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == neg)
		{
			neg.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == sepia)
		{
			sepia.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == original)
		{
			picture.show();
		}
	}
}



Only ONE LINE in your main
the rest should be done within a Photo object context
main() is just used to create a Photo object after that all should be done within it

and true that you also need to add an actionListener to the button

sepia.addActionListener(this);

this reference you actual Photo ocbject which has an actionPerformed() method
Was This Post Helpful? 2
  • +
  • -

#25 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 09:56 PM

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class Photo implements ActionListener 
{
    Picture picture;
    String filename;
	Pixel[] array;
	public JButton neg;
	public JButton original;
	public JButton sepia;
	public JButton bw;
    Photo(String filename) 
	{
		this.picture = new Picture();
        this.filename = filename;
		this.array = picture.getPixels();
		neg.addActionListener(this);
		original.addActionListener(this);
		bw.addActionListener(this);
		sepia.addActionListener(this);
		picture.load(filename);
		
		JFrame gui = new JFrame("Photo Manipulation");
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel buttons = new JPanel();
		buttons.setLayout(new GridLayout(2,2));
		JButton bw = new JButton();
		bw.setText("Black and White");
		buttons.add(bw);
		JButton neg = new JButton();
		neg.setText("Negative");
		buttons.add(neg);
		JButton sepia = new JButton();
		sepia.setText("Sepia");
		buttons.add(sepia);
		JButton original = new JButton();
		original.setText("Original");
		buttons.add(original);
		
		gui.getContentPane().add(buttons);
		gui.pack();
		gui.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == bw)
		{	
			bw.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						int w = (r+b+g)/3;
						temparray[i].setRed(w);
						temparray[i].setGreen(w);
						temparray[i].setBlue(w);
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == neg)
		{
			neg.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == sepia)
		{
			sepia.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						r=255-r;
						g=255-g;
						b=255-b;
						temparray[i].setRed(r);
						temparray[i].setGreen(g);
						temparray[i].setBlue(B)/>;
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == original)
		{
			original.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					picture.show();
				}
			});
		}
	}
    public static void main(String[] arg) 
	{
		Photo phot = new Photo("peter.jpg");
	}
}



Do you mean like this? if so, I get NullPointerExceptions thrown at me :(

This post has been edited by RUFerret: 17 December 2010 - 10:02 PM

Was This Post Helpful? 0
  • +
  • -

#26 pbl   User is offline

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

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

Re: GUI Implementation Errors

Posted 17 December 2010 - 10:14 PM

not

JButton bw = new JButton();

this will create a new variable bw to hold a JButton
you have already JButton bw; declared in your instance variables. So

bw = new JButton(); // do not created a new bw use the one I have already defined

you will also need

bw.addActionListener(this);

also your actionPerformed code is really illogic... you add actionListener to buttons who already have some

from
	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == bw)
		{	
			bw.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
						int r = temparray[i].getRed();
						int g = temparray[i].getGreen();
						int b = temparray[i].getBlue();
						int w = (r+b+g)/3;
						temparray[i].setRed(w);
						temparray[i].setGreen(w);
						temparray[i].setBlue(w);
					}
					temp.show();
				}
			});
		}
		else if (event.getSource() == neg)
		{
			neg.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					Picture temp = new Picture();
					temp.load(filename);
					Pixel[] temparray = temp.getPixels();
					for (int i = 0; i<temparray.length; i++)
					{
...


to
	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == bw)
		{	
			Picture temp = new Picture();
			temp.load(filename);
			Pixel[] temparray = temp.getPixels();
			for (int i = 0; i<temparray.length; i++)
			{
				int r = temparray[i].getRed();
				int g = temparray[i].getGreen();
				int b = temparray[i].getBlue();
				int w = (r+b+g)/3;
				temparray[i].setRed(w);
				temparray[i].setGreen(w);
				temparray[i].setBlue(w);
			}
		}
		else if (event.getSource() == neg)
		{
			Picture temp = new Picture();
			temp.load(filename);
			Pixel[] temparray = temp.getPixels();
			for (int i = 0; i<temparray.length; i++)
			{


Fix your code then will se for the null pointer exception
Was This Post Helpful? 0
  • +
  • -

#27 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 10:25 PM

and lo and behold! GUI photo manipulation!!!

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;
public class Photo implements ActionListener 
{
    Picture picture;
    String filename;
	Pixel[] array;
	public JButton neg;
	public JButton original;
	public JButton sepia;
	public JButton bw;
    Photo(String filename) 
	{
		this.picture = new Picture();
        this.filename = filename;
		this.array = picture.getPixels();
		picture.load(filename);
		
		JFrame gui = new JFrame("Photo Manipulation");
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel buttons = new JPanel();
		buttons.setLayout(new GridLayout(2,2));
		bw = new JButton();
		bw.addActionListener(this);
		bw.setText("Black and White");
		buttons.add(bw);
		neg = new JButton();
		neg.addActionListener(this);
		neg.setText("Negative");
		buttons.add(neg);
		sepia = new JButton();
		sepia.addActionListener(this);
		sepia.setText("Sepia");
		buttons.add(sepia);
		original = new JButton();
		original.addActionListener(this);
		original.setText("Original");
		buttons.add(original);
		
		gui.getContentPane().add(buttons);
		gui.pack();
		gui.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		if (event.getSource() == bw)
		{	
			Picture temp = new Picture();
			temp.load(filename);
			Pixel[] temparray = temp.getPixels();
			for (int i = 0; i<temparray.length; i++)
			{
				int r = temparray[i].getRed();
				int g = temparray[i].getGreen();
				int b = temparray[i].getBlue();
				int w = (r+b+g)/3;
				temparray[i].setRed(w);
				temparray[i].setGreen(w);
				temparray[i].setBlue(w);
			}
			temp.show();
		}
		else if (event.getSource() == neg)
		{
			Picture temp = new Picture();
			temp.load(filename);
			Pixel[] temparray = temp.getPixels();
			for (int i = 0; i<temparray.length; i++)
			{
				int r = temparray[i].getRed();
				int g = temparray[i].getGreen();
				int b = temparray[i].getBlue();
				r=255-r;
				g=255-g;
				b=255-b;
				temparray[i].setRed(r);
				temparray[i].setGreen(g);
				temparray[i].setBlue(B)/>;
			}
			temp.show();
		}
		else if (event.getSource() == sepia)
		{
			Picture temp = new Picture();
		temp.load(filename);
		Pixel[] temparray = temp.getPixels();
		for (int i = 0; i<temparray.length; i++)
		{
			int r = temparray[i].getRed();
			int g = temparray[i].getGreen();
			int b = temparray[i].getBlue();		
			int w = (r+b+g)/3;
			temparray[i].setRed(w);
			temparray[i].setGreen(w);
			temparray[i].setBlue(w);
			r=w;
			g=w;
			b=w;
			if (r < 63)
			{ 
				r=(int)(r*1.1); 
				b=(int)(b*.9);
				temparray[i].setRed(r);
				temparray[i].setBlue(B)/>;
			} 
			if (r > 62 && r < 192)
			{
				r=(int)(r*1.15); 
				b=(int)(b*.85); 
				temparray[i].setRed(r);
				temparray[i].setBlue(B)/>;
				if (r  >191)
				{ 
					r=(int)(r*1.08); 
					temparray[i].setRed(r);
					if (r> 255)
					{ 
					r=255; 
					b=(int)(b*.93); 
					temparray[i].setRed(r);
					temparray[i].setBlue(B)/>;
					}
				}
			}
		}
		temp.show();
		}
		else if (event.getSource() == original)
		{
			picture.show();
		}
	}
    public static void main(String[] arg) 
	{
		Photo phot = new Photo("peter.jpg");
	}
}



Since y'all prolly don't have peter.jpg, enter your own picture and try it out!

Thanks for the help, I learned a lot about GUIs!
Was This Post Helpful? 0
  • +
  • -

#28 pbl   User is offline

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

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

Re: GUI Implementation Errors

Posted 17 December 2010 - 10:53 PM

View PostRUFerret, on 17 December 2010 - 11:25 PM, said:

Thanks for the help, I learned a lot about GUIs!

It is not that much about GUI
It is about:
- what the main() method is for
- what is an instance variable
- what is a variable local to a method
- what an object is and how it's variables are accessed throiught that object context

:^:
Was This Post Helpful? 0
  • +
  • -

#29 RUFerret   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 17-December 10

Re: GUI Implementation Errors

Posted 17 December 2010 - 11:01 PM

Bah, how true!

Now I'm trying to make a .jar file so I can open it at will.

I type in..

echo Main-Class: photo

jar cvf photo.jar manifest.txt *.class

photo.jar

and I get the failed to load attribute error. I go in and place a new line in the manifest.txt and I get another error.. what am I doing wrong? (I litterally learned all that off google 5 minutes ago, so I have no idea what I'm doing)
Was This Post Helpful? 0
  • +
  • -

#30 pbl   User is offline

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

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

Re: GUI Implementation Errors

Posted 19 December 2010 - 12:19 AM

If you have a manifest file you have to specify the fact

jar cmvf photo.jar manifest.txt *.class

This post has been edited by pbl: 19 December 2010 - 12:30 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2