Could somebody please explain and show me the right way?
Thank you.
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class photo implements ActionListener
{
public JButton bw;
public JButton neg;
public JButton sepia;
public JButton original;
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Picture photo = new Picture();
String file = "peter.jpg";
photo.load(file);
Pixel[] array = photo.getPixels();
photo function = new photo();
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("Black and White");
buttons.add(original);
gui.getContentPane().add(buttons);
gui.pack();
gui.setVisible(true);
}
public void actionPerformed(ActionEvent event, Pixel[] array, Picture photo, String file, photo function)
{
if (event.getSource() == bw)
{
function.bw(array,photo,file);
}
else if (event.getSource() == neg)
{
function.neg(array,photo,file);
}
else if (event.getSource() == sepia)
{
function.sepia(array,photo,file);
}
else if (event.getSource() == original)
{
photo.show();
}
}
public void GUI(JButton a, JButton b, JButton c, JButton d)
{
bw = a;
neg = b;
sepia = c;
original = d;
bw.addActionListener(this);
neg.addActionListener(this);
sepia.addActionListener(this);
original.addActionListener(this);
}
public void bw(Pixel[] array, Picture photo, String file)
{
Picture temp = new Picture();
temp.load(file);
Pixel[] temparray = temp.getPixels();
for (int i = 0; i<array.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();
}
public void sepia(Pixel[] array, Picture photo, String file)
{
Picture temp = new Picture();
temp.load(file);
Pixel[] temparray = temp.getPixels();
for (int i = 0; i<array.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();
}
public void neg(Pixel[] array, Picture photo, String file)
{
Picture temp = new Picture();
temp.load(file);
Pixel[] temparray = temp.getPixels();
for (int i = 0; i<array.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();
}
public void random(Pixel[] array, Picture photo, String file)
{
Random rand = new Random();
Picture temp = new Picture();
temp.load(file);
Pixel[] temparray = temp.getPixels();
for (int i = 0; i<array.length; i++)
{
temparray[i].setRed(rand.nextInt(255));
temparray[i].setGreen(rand.nextInt(255));
temparray[i].setBlue(rand.nextInt(255));
}
}
}
ERROR:
photo.java:4: photo is not abstract and does not override abstract method action
Performed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
public class photo implements ActionListener
^
photo.java:23: cannot find symbol
symbol : class GridLayout
The last one I KNOW it's a small problem, since it's the right code (from my other GUI that works T_T)
location: class photo
buttons.setLayout(new GridLayout(2,2));

New Topic/Question
Reply



MultiQuote








|