Restore
This commit is contained in:
BIN
Labs/Lab11/Lab 11 Requirements.pdf
Normal file
BIN
Labs/Lab11/Lab 11 Requirements.pdf
Normal file
Binary file not shown.
0
Labs/Lab11/Lab11_2230026071/.metadata/.lock
Normal file
0
Labs/Lab11/Lab11_2230026071/.metadata/.lock
Normal file
53
Labs/Lab11/Lab11_2230026071/.metadata/.log
Normal file
53
Labs/Lab11/Lab11_2230026071/.metadata/.log
Normal file
@@ -0,0 +1,53 @@
|
||||
!SESSION 2023-05-04 09:38:20.774 -----------------------------------------------
|
||||
eclipse.buildId=4.24.0.I20220607-0700
|
||||
java.version=17.0.3
|
||||
java.vendor=Eclipse Adoptium
|
||||
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
|
||||
Framework arguments: -product org.eclipse.epp.package.jee.product -product org.eclipse.epp.package.jee.product
|
||||
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product -data C:\Users\s230026071\Desktop\Lab11_2230026071 -product org.eclipse.epp.package.jee.product
|
||||
|
||||
!ENTRY org.eclipse.jface 2 0 2023-05-04 09:38:24.002
|
||||
!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation.
|
||||
!SUBENTRY 1 org.eclipse.jface 2 0 2023-05-04 09:38:24.002
|
||||
!MESSAGE A conflict occurred for CTRL+SHIFT+T:
|
||||
Binding(CTRL+SHIFT+T,
|
||||
ParameterizedCommand(Command(org.eclipse.jdt.ui.navigate.open.type,Open Type,
|
||||
Open a type in a Java editor,
|
||||
Category(org.eclipse.ui.category.navigate,Navigate,null,true),
|
||||
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@4c81e7c2,
|
||||
,,true),null),
|
||||
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||
org.eclipse.ui.contexts.window,,,system)
|
||||
Binding(CTRL+SHIFT+T,
|
||||
ParameterizedCommand(Command(org.eclipse.lsp4e.symbolinworkspace,Go to Symbol in Workspace,
|
||||
,
|
||||
Category(org.eclipse.lsp4e.category,Language Servers,null,true),
|
||||
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@4fe8e318,
|
||||
,,true),null),
|
||||
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||
org.eclipse.ui.contexts.window,,,system)
|
||||
!SUBENTRY 1 org.eclipse.jface 2 0 2023-05-04 09:38:24.002
|
||||
!MESSAGE A conflict occurred for ALT+SHIFT+R:
|
||||
Binding(ALT+SHIFT+R,
|
||||
ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.rename.element,Rename - Refactoring ,
|
||||
Rename the selected element,
|
||||
Category(org.eclipse.jdt.ui.category.refactoring,Refactor - Java,Java Refactoring Actions,true),
|
||||
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@21e15093,
|
||||
,,true),null),
|
||||
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||
org.eclipse.ui.contexts.window,,,system)
|
||||
Binding(ALT+SHIFT+R,
|
||||
ParameterizedCommand(Command(org.eclipse.ui.edit.rename,Rename,
|
||||
Rename the selected item,
|
||||
Category(org.eclipse.ui.category.file,File,null,true),
|
||||
org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@62cf873a,
|
||||
,,true),null),
|
||||
org.eclipse.ui.defaultAcceleratorConfiguration,
|
||||
org.eclipse.ui.contexts.window,,,system)
|
||||
|
||||
!ENTRY org.eclipse.egit.ui 2 0 2023-05-04 09:38:27.646
|
||||
!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git
|
||||
user global configuration and to define the default location to store repositories: 'C:\Users\s230026071'. If this is
|
||||
not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and
|
||||
EGit might behave differently since they see different configuration options.
|
||||
This warning can be switched off on the Team > Git > Confirmations and Warnings preference page.
|
||||
@@ -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=
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user