hw4: init
This commit is contained in:
parent
19141831c8
commit
8dd6533d47
29
hw4/.gitignore
vendored
Normal file
29
hw4/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
8
hw4/.idea/.gitignore
generated
vendored
Normal file
8
hw4/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
5
hw4/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
hw4/.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
6
hw4/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
hw4/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
6
hw4/.idea/misc.xml
generated
Normal file
6
hw4/.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
hw4/.idea/modules.xml
generated
Normal file
8
hw4/.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/hw4.iml" filepath="$PROJECT_DIR$/hw4.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
6
hw4/.idea/vcs.xml
generated
Normal file
6
hw4/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
24
hw4/README.md
Normal file
24
hw4/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Programming Assignment 4 - Shape Displayer
|
||||
|
||||
## Requirements
|
||||
|
||||
The user interacts with the application as follows:
|
||||
|
||||
- Initially, the program displays three buttons on the top of the frame and a
|
||||
blank large area of a user-defined JPanel below the buttons. The buttons
|
||||
display a car, a snow man, and a composite shape of your choice, respectively.
|
||||
You are allowed to borrow the CarShape.java from the text book. Make sure to
|
||||
acknowledge that the code is from the text book. The composite shape of your
|
||||
choice should consist of at least 4 primitive shapes, but doesn't have to be
|
||||
fancy.
|
||||
- When the user clicks on one of the buttons, the shape displayed on the clicked
|
||||
button becomes the current shape. The icon representing the current shape
|
||||
should outline the shape as shown below in the sample output. When a mouse is
|
||||
clicked on the user-defined JPanel, the current shape is drawn on the position
|
||||
which the mouse was pressed on.
|
||||
- The current shape can be changed by clicking one of the buttons.
|
||||
- The application should be reusable by any CompositeShape.
|
||||
- Your design should be object-oriented including ShapeDisplayer(with main
|
||||
method), CarShape, SnowMan, and Your_own_shape classes. Also, it should
|
||||
include interface CompositeShape.java and a concrete class ShapeIcon. You may
|
||||
include more classes to your design.
|
11
hw4/hw4.iml
Normal file
11
hw4/hw4.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
71
hw4/src/ShapeDisplayer.java
Normal file
71
hw4/src/ShapeDisplayer.java
Normal file
@ -0,0 +1,71 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class ShapeDisplayer {
|
||||
public static void main(String[] args) {
|
||||
// Create and configure the main frame on the Event Dispatch Thread
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
JFrame frame = new JFrame("Mancala");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(800, 400);
|
||||
|
||||
// Create buttons panel
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new FlowLayout());
|
||||
|
||||
// Create placeholder shapes
|
||||
JButton carButton = new JButton(new PlaceholderIcon(Color.RED));
|
||||
JButton snowmanButton = new JButton(new PlaceholderIcon(Color.BLUE));
|
||||
JButton compositeButton = new JButton(new PlaceholderIcon(Color.GREEN));
|
||||
|
||||
|
||||
// Add buttons to the panel
|
||||
buttonPanel.add(carButton);
|
||||
buttonPanel.add(snowmanButton);
|
||||
buttonPanel.add(compositeButton);
|
||||
|
||||
// Add buttons panel to the top of the frame
|
||||
frame.add(buttonPanel, BorderLayout.NORTH);
|
||||
|
||||
// Add drawing panel
|
||||
JPanel drawingPanel = new JPanel();
|
||||
drawingPanel.setBackground(Color.WHITE);
|
||||
frame.add(drawingPanel, BorderLayout.CENTER);
|
||||
|
||||
// Center the frame on the screen and make it visible
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class PlaceholderIcon implements Icon {
|
||||
private final Color color;
|
||||
private static final int WIDTH = 60;
|
||||
private static final int HEIGHT = 40;
|
||||
|
||||
public PlaceholderIcon(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
Rectangle2D.Double rect = new Rectangle2D.Double(x + 5, y + 5, WIDTH - 10, HEIGHT - 10);
|
||||
g2.setColor(color);
|
||||
g2.fill(rect);
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.draw(rect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconWidth() {
|
||||
return WIDTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconHeight() {
|
||||
return HEIGHT;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user