This commit is contained in:
ldy
2026-03-01 23:18:55 -05:00
commit 67f753a5d1
3087 changed files with 218259 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Question4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

Binary file not shown.

View File

@@ -0,0 +1,32 @@
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.setLocationRelativeTo(null);
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);
}
}

View File

@@ -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);
}
}
}

View File

@@ -0,0 +1,13 @@
public class Start {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new MyFrame();
}
});
}
}