Skip to content
Snippets Groups Projects
Commit 6163c2c6 authored by Chang Che Hao's avatar Chang Che Hao
Browse files

Initial commit

parent 3f89de59
No related branches found
No related tags found
3 merge requests!8Master,!3Master to hai-branch,!1Initial
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RectangularShape;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class DrawingArea extends JPanel {
/// enum for all different mode ///
enum Mode { FREEHAND, LINE, CIRCLE, RECTANGLE, OVAL, ERASE }
/// Canvas size parameter ///
private final static int AREA_WIDTH = 600;
private final static int AREA_HEIGHT = 500;
// private int initialX, initialY, currentX, currentY, finalX, finalY;
private Point startPoint;
private Point previousPoint;
private Point currentPoint;
/// Create a empty canvas ///
private BufferedImage image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
/// Default mode and color ///
private Color shapeColor = new Color(0, 0, 0);
private Mode currentMode = Mode.FREEHAND;
/// Shape to be drawn on the canvas ///
private Shape drawing;
/// Drawing tool
private Graphics2D g2 = (Graphics2D) image.getGraphics();
public DrawingArea() {
/// Antialiasing the graphic for smoothness ///
// g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
/// Set Background color ///
setBackground(Color.WHITE);
/// Non-buffered drawing ///
setDoubleBuffered(false);
/// Mouse listeners for pressing///
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
startPoint = previousPoint = e.getPoint();
/// Instantiate object based on current mode ///
switch (currentMode) {
case FREEHAND:
case LINE:
drawing = new Line2D.Double();
break;
case ERASE:
case CIRCLE:
case OVAL:
drawing = new Ellipse2D.Double();
break;
case RECTANGLE:
drawing = new Rectangle2D.Double();
break;
}
}
});
/// Mouse motion listeners for dragging ///
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
currentPoint = e.getPoint();
int x = Math.min(startPoint.x, e.getX());
int y = Math.min(startPoint.y, e.getY());
int width = Math.abs(startPoint.x - e.getX());
int height = Math.abs(startPoint.y - e.getY());
switch (currentMode) {
/// Freehand drawing is continuously drawing line from current point to previous point ///
case FREEHAND:
((Line2D) drawing).setLine(currentPoint, previousPoint);
g2.setColor(shapeColor);
g2.draw(drawing);
previousPoint = currentPoint;
break;
/// Single line ///
case LINE:
((Line2D) drawing).setLine(startPoint, currentPoint);
break;
/// Eraser is continuously drawing "small white circle" from current point to previous point ///
case ERASE:
((Ellipse2D) drawing).setFrame(currentPoint.getX(), currentPoint.getY(), 10, 10);
g2.setColor(Color.WHITE);
g2.fill(drawing);
g2.draw(drawing);
break;
/// Single circle (How to draw more intuitively?)///
case CIRCLE:
double radius = Math.sqrt(width * width + height * height);
// ((Ellipse2D) drawing).setFrame(x, y, radius, radius);
((Ellipse2D) drawing).setFrame(startPoint.getX() - radius, startPoint.getY() - radius, 2 * radius, 2 * radius);
break;
/// Single oval ///
case OVAL:
((Ellipse2D) drawing).setFrame(x, y, width, height);
break;
/// Single rectangle ///
case RECTANGLE:
((Rectangle2D) drawing).setFrame(x, y, width, height);
break;
}
repaint();
}
});
/// Mouse listener for releasing ///
addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e) {
/// Draw the final drawing to the buffered image ///
switch (currentMode) {
case OVAL:
case RECTANGLE:
case CIRCLE:
/// Abort drawing if 2D has no width or height ///
if (((RectangularShape) drawing).getWidth() == 0 || ((RectangularShape) drawing).getHeight() == 0) {
break;
}
case FREEHAND:
case LINE:
// Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(shapeColor);
/// Uncomment the line below to fill the shapes with color ///
// g2.fill(drawing);
g2.draw(drawing);
}
g2 = (Graphics2D) image.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(shapeColor);
/// This repaint is needed if we want to fill the drawing shape with color
repaint();
drawing = null;
}
});
}
@Override
public Dimension getPreferredSize()
{
return isPreferredSizeSet() ?
super.getPreferredSize() : new Dimension(AREA_WIDTH, AREA_HEIGHT);
}
/// Create a white image to clear previous drawing ///
public void clear() {
image = new BufferedImage(AREA_WIDTH, AREA_HEIGHT, BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) image.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
repaint();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
/// Draw the whole image on JPanel ///
if (image != null) {
g.drawImage(image, 0, 0, null);
}
/// Draw temporary shape ///
if (drawing != null) {
Graphics2D g2 = (Graphics2D) g;
/// Eraser has no border color ///
Color borderColor = currentMode != Mode.ERASE ? shapeColor : Color.WHITE;
g2.setColor(borderColor);
g2.draw(drawing);
}
}
/// File manipulations (PNG only) ///
public void saveFile() {
try {
ImageIO.write(image, "PNG", new File("Saved_White_Board.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void saveAsFile(File file) {
try {
ImageIO.write(image, "PNG", file);
} catch (IOException e) {
e.printStackTrace();
}
}
public void openFile(File file) {
try {
image = ImageIO.read(file);
} catch (IOException e) {
e.printStackTrace();
}
repaint();
}
/// Drawing mode setters ///
public void setModeFreehand() {
currentMode = Mode.FREEHAND;
}
public void setModeLine() {
currentMode = Mode.LINE;
}
public void setModeCircle() {
currentMode = Mode.CIRCLE;
}
public void setModeRectangle() {
currentMode = Mode.RECTANGLE;
}
public void setModeOval() {
currentMode = Mode.OVAL;
}
public void setModeErase() {
currentMode = Mode.ERASE;
}
/// Drawing color setters ///
public void setColorAqua() {
shapeColor = new Color(0,255, 255);
}
public void setColorBlack() {
shapeColor = new Color(0, 0, 0);
}
public void setColorBlue() {
shapeColor = new Color(0, 0, 255);
}
public void setColorFuchsia() {
shapeColor = new Color(255, 0, 255);
}
public void setColorGray() {
shapeColor = new Color(128, 128, 128);
}
public void setColorGreen() {
shapeColor = new Color(0, 128, 0);
}
public void setColorLime() {
shapeColor = new Color(0, 255, 0);
}
public void setColorMaroon() {
shapeColor = new Color(128,0, 0);
}
public void setColorNavy() {
shapeColor = new Color(0, 0, 128);
}
public void setColorOlive() {
shapeColor = new Color(128, 128, 0);
}
public void setColorPurple() {
shapeColor = new Color(128, 0, 128);
}
public void setColorRed() {
shapeColor = new Color(255, 0, 0);
}
public void setColorSilver() {
shapeColor = new Color(192, 192, 192);
}
public void setColorTeal() {
shapeColor = new Color(0, 128, 128);
}
public void setColorWhite() {
shapeColor = new Color(255, 255, 255);
}
public void setColorYellow() {
shapeColor = new Color(255, 255, 0);
}
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class PaintClientGUI {
String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser"};
String[] colors = {"Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow"};
JFrame frame;
JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn;
JComboBox colorOptions;
JComboBox shapeOptions;
DrawingArea drawingArea;
JFileChooser fileChooser= new JFileChooser();
JPanel toolbox = new JPanel();
JPanel fileControl = new JPanel();
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
/// Clear button ///
if (e.getSource() == clearBtn) {
drawingArea.clear();
/// Create new canvas ///
} else if (e.getSource() == newBtn) {
int returnVal = JOptionPane.showConfirmDialog(new JFrame(), "Save your current whiteboard?", "Save or Discard", JOptionPane.YES_NO_CANCEL_OPTION);
if (returnVal == JOptionPane.YES_OPTION) {
drawingArea.saveFile();
drawingArea.clear();
} else if (returnVal == JOptionPane.NO_OPTION) {
drawingArea.clear();
}
// Open file (PNG only) ///
} else if (e.getSource() == openBtn) {
int returnVal = fileChooser.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.openFile(file);
}
/// Save under project directory without filename (PNG file with default filename) ///
} else if (e.getSource() == saveBtn) {
drawingArea.saveFile();
/// Save with other filename (PNG only) ///
} else if (e.getSource() == saveAsBtn) {
fileChooser = new JFileChooser();
int returnVal = fileChooser.showSaveDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.saveAsFile(file);
}
/// Close application ///
} else if (e.getSource() == closeBtn) {
System.exit(0);
/// Choose drawing color ///
} else if (e.getSource() == colorOptions) {
String colorChosen = (String) colorOptions.getSelectedItem();
switch (colorChosen){
case "Aqua":
drawingArea.setColorAqua();
break;
case "Black":
drawingArea.setColorBlack();
break;
case "Blue":
drawingArea.setColorBlue();
break;
case "Fuchsia":
drawingArea.setColorFuchsia();
break;
case "Gray":
drawingArea.setColorGray();
break;
case "Green":
drawingArea.setColorGreen();
break;
case "Lime":
drawingArea.setColorLime();
break;
case "Maroon":
drawingArea.setColorMaroon();
break;
case "Navy":
drawingArea.setColorNavy();
break;
case "Olive":
drawingArea.setColorOlive();
break;
case "Purple":
drawingArea.setColorPurple();
break;
case "Red":
drawingArea.setColorRed();
break;
case "Silver":
drawingArea.setColorSilver();
break;
case "Teal":
drawingArea.setColorTeal();
break;
case "White":
drawingArea.setColorWhite();
break;
case "Yellow":
drawingArea.setColorYellow();
break;
}
/// Choose drawing tool ///
} else if (e.getSource() == shapeOptions) {
String shapeChosen = (String) shapeOptions.getSelectedItem();
switch (shapeChosen){
case "Freehand":
drawingArea.setModeFreehand();
break;
case "Line":
drawingArea.setModeLine();
break;
case "Circle":
drawingArea.setModeCircle();
break;
case "Rectangle":
drawingArea.setModeRectangle();
break;
case "Oval":
drawingArea.setModeOval();
break;
case "Eraser":
drawingArea.setModeErase();
break;
}
}
}
};
/// Main program ///
public static void main(String[] args) {
new PaintClientGUI().createAndShowGUI();
}
/// GUI setup ///
private void createAndShowGUI() {
/// Main drawing area ///
drawingArea = new DrawingArea();
/// Set up main frame and container ///
frame = new JFrame("Shared Whiteboard System");
JFrame.setDefaultLookAndFeelDecorated(true);
Container content = frame.getContentPane();
content.setLayout(new BorderLayout());
/// Set up elements ///
shapeOptions = new JComboBox(shapes);
shapeOptions.addActionListener(actionListener);
colorOptions = new JComboBox(colors);
colorOptions.setSelectedItem("Black");
colorOptions.addActionListener(actionListener);
clearBtn = new JButton("Clear");
clearBtn.addActionListener(actionListener);
newBtn = new JButton("New");
newBtn.addActionListener(actionListener);
openBtn = new JButton("Open");
openBtn.addActionListener(actionListener);
saveBtn = new JButton("Save");
saveBtn.addActionListener(actionListener);
saveAsBtn = new JButton("Save As");
saveAsBtn.addActionListener(actionListener);
closeBtn = new JButton("Close");
closeBtn.addActionListener(actionListener);
/// Toolbox panel ///
toolbox.add(colorOptions);
toolbox.add(shapeOptions);
toolbox.add(clearBtn);
/// File control panel ///
fileControl.add(newBtn);
fileControl.add(openBtn);
fileControl.add(saveBtn);
fileControl.add(saveAsBtn);
fileControl.add(closeBtn);
/// Layout ///
content.add(fileControl, BorderLayout.NORTH);
content.add(drawingArea);
content.add(toolbox, BorderLayout.SOUTH);
/// Miscellaneous ///
frame.setSize(800, 600);
frame.setLocationRelativeTo( null );
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class PaintGUI {
String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser"};
String[] colors = {"Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow"};
JFrame frame;
JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn;
JComboBox colorOptions;
JComboBox shapeOptions;
DrawingArea drawingArea;
JFileChooser fileChooser= new JFileChooser();
JPanel toolbox = new JPanel();
JPanel fileControl = new JPanel();
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
/// Clear button ///
if (e.getSource() == clearBtn) {
drawingArea.clear();
/// Create new canvas ///
} else if (e.getSource() == newBtn) {
int returnVal = JOptionPane.showConfirmDialog(new JFrame(), "Save your current whiteboard?", "Save or Discard", JOptionPane.YES_NO_CANCEL_OPTION);
if (returnVal == JOptionPane.YES_OPTION) {
drawingArea.saveFile();
drawingArea.clear();
} else if (returnVal == JOptionPane.NO_OPTION) {
drawingArea.clear();
}
// Open file (PNG only) ///
} else if (e.getSource() == openBtn) {
int returnVal = fileChooser.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.openFile(file);
}
/// Save under project directory without filename (PNG file with default filename) ///
} else if (e.getSource() == saveBtn) {
drawingArea.saveFile();
/// Save with other filename (PNG only) ///
} else if (e.getSource() == saveAsBtn) {
fileChooser = new JFileChooser();
int returnVal = fileChooser.showSaveDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.saveAsFile(file);
}
/// Close application ///
} else if (e.getSource() == closeBtn) {
System.exit(0);
/// Choose drawing color ///
} else if (e.getSource() == colorOptions) {
String colorChosen = (String) colorOptions.getSelectedItem();
switch (colorChosen){
case "Aqua":
drawingArea.setColorAqua();
break;
case "Black":
drawingArea.setColorBlack();
break;
case "Blue":
drawingArea.setColorBlue();
break;
case "Fuchsia":
drawingArea.setColorFuchsia();
break;
case "Gray":
drawingArea.setColorGray();
break;
case "Green":
drawingArea.setColorGreen();
break;
case "Lime":
drawingArea.setColorLime();
break;
case "Maroon":
drawingArea.setColorMaroon();
break;
case "Navy":
drawingArea.setColorNavy();
break;
case "Olive":
drawingArea.setColorOlive();
break;
case "Purple":
drawingArea.setColorPurple();
break;
case "Red":
drawingArea.setColorRed();
break;
case "Silver":
drawingArea.setColorSilver();
break;
case "Teal":
drawingArea.setColorTeal();
break;
case "White":
drawingArea.setColorWhite();
break;
case "Yellow":
drawingArea.setColorYellow();
break;
}
/// Choose drawing tool ///
} else if (e.getSource() == shapeOptions) {
String shapeChosen = (String) shapeOptions.getSelectedItem();
switch (shapeChosen){
case "Freehand":
drawingArea.setModeFreehand();
break;
case "Line":
drawingArea.setModeLine();
break;
case "Circle":
drawingArea.setModeCircle();
break;
case "Rectangle":
drawingArea.setModeRectangle();
break;
case "Oval":
drawingArea.setModeOval();
break;
case "Eraser":
drawingArea.setModeErase();
break;
}
}
}
};
/// Main program ///
public static void main(String[] args) {
new PaintGUI().createAndShowGUI();
}
/// GUI setup ///
private void createAndShowGUI() {
/// Main drawing area ///
drawingArea = new DrawingArea();
/// Set up main frame and container ///
frame = new JFrame("Shared Whiteboard System");
JFrame.setDefaultLookAndFeelDecorated(true);
Container content = frame.getContentPane();
content.setLayout(new BorderLayout());
/// Set up elements ///
shapeOptions = new JComboBox(shapes);
shapeOptions.addActionListener(actionListener);
colorOptions = new JComboBox(colors);
colorOptions.setSelectedItem("Black");
colorOptions.addActionListener(actionListener);
clearBtn = new JButton("Clear");
clearBtn.addActionListener(actionListener);
newBtn = new JButton("New");
newBtn.addActionListener(actionListener);
openBtn = new JButton("Open");
openBtn.addActionListener(actionListener);
saveBtn = new JButton("Save");
saveBtn.addActionListener(actionListener);
saveAsBtn = new JButton("Save As");
saveAsBtn.addActionListener(actionListener);
closeBtn = new JButton("Close");
closeBtn.addActionListener(actionListener);
/// Toolbox panel ///
toolbox.add(colorOptions);
toolbox.add(shapeOptions);
toolbox.add(clearBtn);
/// File control panel ///
fileControl.add(newBtn);
fileControl.add(openBtn);
fileControl.add(saveBtn);
fileControl.add(saveAsBtn);
fileControl.add(closeBtn);
/// Layout ///
content.add(fileControl, BorderLayout.NORTH);
content.add(drawingArea);
content.add(toolbox, BorderLayout.SOUTH);
/// Miscellaneous ///
frame.setSize(800, 600);
frame.setLocationRelativeTo( null );
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class PaintServerGUI {
String[] shapes = {"Freehand", "Line", "Circle", "Rectangle", "Oval", "Eraser"};
String[] colors = {"Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow"};
JFrame frame;
JButton clearBtn, newBtn, openBtn, saveBtn, saveAsBtn, closeBtn;
JComboBox colorOptions;
JComboBox shapeOptions;
DrawingArea drawingArea;
JFileChooser fileChooser= new JFileChooser();
JPanel toolbox = new JPanel();
JPanel fileControl = new JPanel();
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
/// Clear button ///
if (e.getSource() == clearBtn) {
drawingArea.clear();
/// Create new canvas ///
} else if (e.getSource() == newBtn) {
int returnVal = JOptionPane.showConfirmDialog(new JFrame(), "Save your current whiteboard?", "Save or Discard", JOptionPane.YES_NO_CANCEL_OPTION);
if (returnVal == JOptionPane.YES_OPTION) {
drawingArea.saveFile();
drawingArea.clear();
} else if (returnVal == JOptionPane.NO_OPTION) {
drawingArea.clear();
}
// Open file (PNG only) ///
} else if (e.getSource() == openBtn) {
int returnVal = fileChooser.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.openFile(file);
}
/// Save under project directory without filename (PNG file with default filename) ///
} else if (e.getSource() == saveBtn) {
drawingArea.saveFile();
/// Save with other filename (PNG only) ///
} else if (e.getSource() == saveAsBtn) {
fileChooser = new JFileChooser();
int returnVal = fileChooser.showSaveDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
drawingArea.saveAsFile(file);
}
/// Close application ///
} else if (e.getSource() == closeBtn) {
System.exit(0);
/// Choose drawing color ///
} else if (e.getSource() == colorOptions) {
String colorChosen = (String) colorOptions.getSelectedItem();
switch (colorChosen){
case "Aqua":
drawingArea.setColorAqua();
break;
case "Black":
drawingArea.setColorBlack();
break;
case "Blue":
drawingArea.setColorBlue();
break;
case "Fuchsia":
drawingArea.setColorFuchsia();
break;
case "Gray":
drawingArea.setColorGray();
break;
case "Green":
drawingArea.setColorGreen();
break;
case "Lime":
drawingArea.setColorLime();
break;
case "Maroon":
drawingArea.setColorMaroon();
break;
case "Navy":
drawingArea.setColorNavy();
break;
case "Olive":
drawingArea.setColorOlive();
break;
case "Purple":
drawingArea.setColorPurple();
break;
case "Red":
drawingArea.setColorRed();
break;
case "Silver":
drawingArea.setColorSilver();
break;
case "Teal":
drawingArea.setColorTeal();
break;
case "White":
drawingArea.setColorWhite();
break;
case "Yellow":
drawingArea.setColorYellow();
break;
}
/// Choose drawing tool ///
} else if (e.getSource() == shapeOptions) {
String shapeChosen = (String) shapeOptions.getSelectedItem();
switch (shapeChosen){
case "Freehand":
drawingArea.setModeFreehand();
break;
case "Line":
drawingArea.setModeLine();
break;
case "Circle":
drawingArea.setModeCircle();
break;
case "Rectangle":
drawingArea.setModeRectangle();
break;
case "Oval":
drawingArea.setModeOval();
break;
case "Eraser":
drawingArea.setModeErase();
break;
}
}
}
};
/// Main program ///
public static void main(String[] args) {
new PaintServerGUI().createAndShowGUI();
}
/// GUI setup ///
private void createAndShowGUI() {
/// Main drawing area ///
drawingArea = new DrawingArea();
/// Set up main frame and container ///
frame = new JFrame("Shared Whiteboard System");
JFrame.setDefaultLookAndFeelDecorated(true);
Container content = frame.getContentPane();
content.setLayout(new BorderLayout());
/// Set up elements ///
shapeOptions = new JComboBox(shapes);
shapeOptions.addActionListener(actionListener);
colorOptions = new JComboBox(colors);
colorOptions.setSelectedItem("Black");
colorOptions.addActionListener(actionListener);
clearBtn = new JButton("Clear");
clearBtn.addActionListener(actionListener);
newBtn = new JButton("New");
newBtn.addActionListener(actionListener);
openBtn = new JButton("Open");
openBtn.addActionListener(actionListener);
saveBtn = new JButton("Save");
saveBtn.addActionListener(actionListener);
saveAsBtn = new JButton("Save As");
saveAsBtn.addActionListener(actionListener);
closeBtn = new JButton("Close");
closeBtn.addActionListener(actionListener);
/// Toolbox panel ///
toolbox.add(colorOptions);
toolbox.add(shapeOptions);
toolbox.add(clearBtn);
/// File control panel ///
fileControl.add(newBtn);
fileControl.add(openBtn);
fileControl.add(saveBtn);
fileControl.add(saveAsBtn);
fileControl.add(closeBtn);
/// Layout ///
content.add(fileControl, BorderLayout.NORTH);
content.add(drawingArea);
content.add(toolbox, BorderLayout.SOUTH);
/// Miscellaneous ///
frame.setSize(800, 600);
frame.setLocationRelativeTo( null );
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment