Restore
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MyPanel myPanel = new MyPanel();
|
||||
myPanel.clearAllPoints();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private static ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear(); //clear array elements
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void undoPoint() {
|
||||
if(points.size() - 1 > 0)
|
||||
points.remove(points.size()-1); //remove last point
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MyPanel myPanel = new MyPanel();
|
||||
myPanel.clearAllPoints();
|
||||
}
|
||||
});
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
System.out.println("x: " + e.getX() + " y: " + e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(Point p: points) {
|
||||
g.drawRect(p.x, p.y, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
public MyPanel() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 1; i < points.size(); ++i) {
|
||||
g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
public class MyFrame {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
for(int i = 1; i < points.size(); ++i) {
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MyPanel.clearAllPoints();
|
||||
}
|
||||
});
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
public class MyPanel {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private static ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void undoPoint() {
|
||||
points.remove(points.size()-1);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private static ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear(); //clear array elements
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void undoPoint() {
|
||||
points.remove(points.size()-1); //remove last point
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(Point p: points) {
|
||||
g.drawRect(p.x, p.y, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private static ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 1; i < points.size(); ++i) {
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private int x = -1;
|
||||
private int y = 1;
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
x = e.getX();
|
||||
y = e.getY();
|
||||
System.out.println("x: " + x + " y: " + y);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(x, y, 1, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
for(int i = 1; i < points.size(); ++i) {
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private int x = -1;
|
||||
private int y = 1;
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
x = e.getX();
|
||||
y = e.getY();
|
||||
System.out.println("x: " + x + " y: " + y);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawRect((int)points.get(0).x, (int)points.get(0).y, 1, 1);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
MyPanel myPanel = new MyPanel();
|
||||
this.add(myPanel, BorderLayout.CENTER);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myPanel.clearAllPoints();
|
||||
}
|
||||
});
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
MyPanel myPanel = new MyPanel();
|
||||
this.add(myPanel, BorderLayout.CENTER);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myPanel.clearAllPoints();
|
||||
}
|
||||
});
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
public MyPanel() {
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
System.out.println("x: " + e.getX() + " y: " + e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
System.out.println("x: " + e.getX() + " y: " + e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private static ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("Undo");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
MyPanel myPanel = new MyPanel();
|
||||
this.add(myPanel, BorderLayout.CENTER);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myPanel.clearAllPoints();
|
||||
}
|
||||
});
|
||||
|
||||
b2.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
myPanel.undoPoint();
|
||||
}
|
||||
});
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MyPanel myPanel = new MyPanel();
|
||||
myPanel.clearAllPoints();
|
||||
}
|
||||
});
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private int x = -1;
|
||||
private int y = 1;
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
x = e.getX();
|
||||
y = e.getY();
|
||||
System.out.println("x: " + x + " y: " + y);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(x, y, 1, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private int x = -1;
|
||||
private int y = 1;
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
x = e.getX();
|
||||
y = e.getY();
|
||||
System.out.println("x: " + x + " y: " + y);
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
g.drawRect(x, y, 1, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
clearAllPoints();
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawRect((int)points.get(0).x, (int)points.get(0).y, 0.5, 0.5);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("Reset");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//button setting
|
||||
b1.addActionListener(new ActionListener() { // Anonymous class.
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
repaint();
|
||||
}
|
||||
});
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
//setVisible
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private static ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//methods
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear(); //clear array
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void undoPoint() {
|
||||
points.remove(points.size()-1); //remove last point
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 1; i < points.size(); ++i) {
|
||||
g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyPanel extends JPanel {
|
||||
//instance variables
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
//constructor
|
||||
public MyPanel() {
|
||||
//mouse listener
|
||||
this.addMouseListener(new MouseAdapter() { // Anonymous class.
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
//if left button clicked
|
||||
if(e.getButton() == MouseEvent.BUTTON1) {
|
||||
Point p = e.getPoint();
|
||||
System.out.println("x: " + p.x + " y: " + p.y);
|
||||
points.add(p);
|
||||
repaint(); //force invoke paintComponent()
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(Color.RED);
|
||||
for(int i = 0; i < points.size(); ++i) {
|
||||
if(i == 0) g.drawLine((int)points.get(0).x, (int)points.get(0).y, (int)points.get(0).x, (int)points.get(0).y);
|
||||
else g.drawLine((int)points.get(i).x, (int)points.get(i).y, (int)points.get(i-1).x, (int)points.get(i-1).y);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllPoints() {
|
||||
points.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class MyFrame extends JFrame {
|
||||
public MyFrame() {
|
||||
//Auxiliary
|
||||
this.setTitle("My Frame Title");
|
||||
this.setSize(400, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
this.setLayout(new BorderLayout());
|
||||
|
||||
//JPanel
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout());
|
||||
this.add(p, BorderLayout.PAGE_START);
|
||||
JButton b1 = new JButton("left");
|
||||
JButton b2 = new JButton("right");
|
||||
p.add(b1);
|
||||
p.add(b2);
|
||||
|
||||
//MyPanel
|
||||
this.add(new MyPanel(), BorderLayout.CENTER);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding=UTF-8
|
||||
version=1
|
||||
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.debug.ui.PREF_LAUNCH_PERSPECTIVES=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\r\n<launchPerspectives/>\r\n
|
||||
preferredTargets=default,org.eclipse.lsp4e.debug.toggleBreakpointTarget\:default|org.eclipse.lsp4e.debug.toggleBreakpointTarget\:org.eclipse.lsp4e.debug.toggleBreakpointTarget|
|
||||
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.codeComplete.visibilityCheck=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.junit.content_assist_favorite_static_members_migrated=true
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.launching.PREF_VM_XML=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>\r\n<vmSettings defaultVM\="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1683164332626">\r\n <vmType id\="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">\r\n <vm id\="1683164332626" name\="jre" path\="C\:\\Eclipse\\plugins\\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.3.v20220515-1416\\jre"/>\r\n </vmType>\r\n</vmSettings>\r\n
|
||||
@@ -0,0 +1,10 @@
|
||||
content_assist_lru_history=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><history maxLHS\="100" maxRHS\="10"/>
|
||||
content_assist_number_of_computers=17
|
||||
content_assist_proposals_background=255,255,255
|
||||
content_assist_proposals_foreground=0,0,0
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.ui.formatterprofiles.version=22
|
||||
spelling_locale_initialized=true
|
||||
typefilter_migrated_2=true
|
||||
useAnnotationsPrefPage=true
|
||||
useQuickDiffPrefPage=true
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jsch.core.hasChangedDefaultWin32SshHome=true
|
||||
@@ -0,0 +1,2 @@
|
||||
areThereWebServices=false
|
||||
eclipse.preferences.version=1
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.m2e.discovery.pref.projects=
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
knownEEFragments=
|
||||
@@ -0,0 +1,5 @@
|
||||
SWITCH_PERSPECTIVE_ON_PROJECT_CREATION=always
|
||||
eclipse.preferences.version=1
|
||||
platformState=1659508920205
|
||||
quickStart=false
|
||||
tipsAndTricks=true
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ui.navigator.ProjectExplorer.filterActivation=\:org.eclipse.jdt.java.ui.filters.HidePackageDeclaration\:org.eclipse.jdt.java.ui.filters.HideOutputFolder\:org.eclipse.buildship.ui.navigator.filter.gradle.subProject\:org.eclipse.ui.navigator.resources.nested.HideTopLevelProjectIfNested\:org.eclipse.buildship.ui.navigator.filter.gradle.buildfolder\:org.eclipse.jdt.java.ui.filters.HideEmptyInnerPackages\:org.eclipse.jst.j2ee.navigator.ui.filters.jetemitters\:org.eclipse.jdt.java.ui.filters.HideInnerClassFiles\:org.eclipse.ui.navigator.resources.filters.startsWithDot\:org.eclipse.jdt.java.ui.filters.HideEmptyLibraryContainers\:org.eclipse.jdt.java.ui.filters.HideImportDeclaration\:org.eclipse.jdt.java.ui.filters.HideSyntheticMembers\:org.eclipse.ui.navigator.resources.nested.HideFolderWhenProjectIsShownAsNested\:
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
showIntro=false
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user