Skip to content

Commit

Permalink
Added 2DGraphics
Browse files Browse the repository at this point in the history
  • Loading branch information
NMKrastev committed Jul 7, 2022
1 parent de8d890 commit ff0cd0c
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 47-KeyBindings/47-KeyBindings.iml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out/production/" />
<output url="file://$MODULE_DIR$/out/production" />
<output-test url="file://$MODULE_DIR$/../out/test/47-KeyBindings" />
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
13 changes: 13 additions & 0 deletions 48-2DGraphics/48-2DGraphics.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out/production/" />
<output-test url="file://$MODULE_DIR$/../out/test/48-2DGraphics" />
<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>
Binary file added 48-2DGraphics/out/production/Frame.class
Binary file not shown.
Binary file added 48-2DGraphics/out/production/Main.class
Binary file not shown.
Binary file added 48-2DGraphics/out/production/Panel.class
Binary file not shown.
18 changes: 18 additions & 0 deletions 48-2DGraphics/src/Frame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import javax.swing.*;
import java.awt.*;

public class Frame extends JFrame {

Panel panel;
Frame() {

panel = new Panel();

this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.add(panel);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);

}
}
8 changes: 8 additions & 0 deletions 48-2DGraphics/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Main {
public static void main(String[] args) {


new Frame();

}
}
38 changes: 38 additions & 0 deletions 48-2DGraphics/src/Panel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import javax.swing.*;
import java.awt.*;

public class Panel extends JPanel {

Image image;
Panel() {
image = new ImageIcon("Sky.png").getImage();
this.setPreferredSize(new Dimension(500, 500));
}

//This method is invoked automatically, there is no need to call it!!!
public void paint(Graphics g) {

Graphics2D g2D = (Graphics2D) g;

g2D.setPaint(Color.red);
//g2D.setStroke(new BasicStroke(5));
//g2D.drawLine(0, 0, 500, 500);
//g2D.drawRect(0,0, 100, 200);
//g2D.fillRect(0, 0, 100, 200);
//g2D.drawOval(100, 100 , 200, 200);
//g2D.fillOval(100, 100 , 200, 200);
//g2D.drawArc(0, 0, 100, 100, 0, 180);
//g2D.fillArc(0, 0, 100, 100, 0, 180);
//g2D.setPaint(Color.white);
//g2D.fillArc(0, 0, 100, 100, 180, 180);
//int[] xPoints = {150, 250, 350};
//int[] yPoints = {300, 150, 300};
//g2D.drawPolygon(xPoints, yPoints, 3);
//g2D.fillPolygon(xPoints, yPoints, 3);
//g2D.setFont(new Font("MV Boli", Font.BOLD, 50));
//g2D.drawString("Text goes here", 50, 50);

g2D.drawImage(image, 0, 0, null);

}
}
Binary file added Sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff0cd0c

Please sign in to comment.