Here is my code
import java.lang.String.*;
import java.lang.Exception.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ImageProcessor extends JFrame implements ActionListener{
// instance variables
private static final int FRAME_WIDTH = 975;
private static final int FRAME_HEIGHT = 725;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private static final int SIDE_BUTTON_WIDTH = 150;
private static final int SIDE_BUTTON_HEIGHT = 150;
private static final int BOTTOM_BUTTON_WIDTH = 80;
private static final int BOTTOM_BUTTON_HEIGHT = 30;
private JButton stats;
private JButton resize;
private JButton brighten;
private JButton darken;
private JButton load;
private JButton quit;
JFileChooser chooser;
String choosertitle;
public static void main(String[] args){
ImageProcessor frame = new ImageProcessor();
frame.setVisible(true);
}
/**
* Constructor for objects of class Calculate
*/
public ImageProcessor(){
Container contentPane;
//Set the frame properties
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setResizable (false);
setTitle ("Image Processor");
setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
contentPane = getContentPane();
contentPane.setLayout(null);
contentPane.setBackground( Color.white );
//Create and Place the Buttons on the frame
stats = new JButton("Stats");
stats.setBounds(825, 0, SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT);
contentPane.add(stats);
resize = new JButton("Resize");
resize.setBounds(825, 150, SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT);
contentPane.add(resize);
brighten = new JButton("Brighten");
brighten.setBounds(825, 300, SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT);
contentPane.add(brighten);
darken = new JButton("Darken");
darken.setBounds(825, 450, SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT);
contentPane.add(darken);
load = new JButton("Load");
load.setBounds(392, 650, BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_HEIGHT);
contentPane.add(load);
quit = new JButton("Quit");
quit.setBounds(503, 650, BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_HEIGHT);
contentPane.add(quit);
//Register this frame as an Action listener of the buttons
stats.addActionListener(this);
resize.addActionListener(this);
brighten.addActionListener(this);
darken.addActionListener(this);
load.addActionListener(this);
quit.addActionListener(this);
add(load);
//Exit program when the viewer is closed
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
//Event handler
public void actionPerformed(ActionEvent event){
if(event.getSource() instanceof JButton){
JButton clickedButton = (JButton) event.getSource();
String buttonText = clickedButton.getText();
if(buttonText.equals("Stats")){
}
if(buttonText.equals("Resize")){
}
if(buttonText.equals("Brighten")){
}
if(buttonText.equals("Darken")){
}
if(buttonText.equals("Load")){
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setAcceptAllFileFilterUsed(true);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): "
+ chooser.getCurrentDirectory());
System.out.println("getSelectedFile() : "
+ chooser.getSelectedFile());
}
else {
System.out.println("No Selection ");
}
}
if(buttonText.equals("Quit")){
System.exit(0);
}
}
}
}

New Topic/Question
Reply




MultiQuote







|