Loading src/main/java/ch14/MyDrawPanel.java +10 −2 Changes for src/main/java/ch14/MyDrawPanel.java: 10 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -2,13 +2,21 @@ package ch14; import javax.swing.*; import java.awt.*; import java.util.Random; class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.orange); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.fillRect(20, 50, 100, 100); Random random = new Random(); int red = random.nextInt(256); int green = random.nextInt(256); int blue = random.nextInt(256); Color randomColor = new Color(red, green, blue); g.setColor(randomColor); g.fillOval(70, 70, 100, 100); } public static void main(String[] args) { Loading src/main/java/ch14/SimpleAnimation.java +8 −8 Changes for src/main/java/ch14/SimpleAnimation.java: 8 added lines, 8 removed lines. Original line number Diff line number Diff line package ch14; import javax.swing.*; import java.awt.Color; import java.awt.Graphics; import java.awt.*; import java.util.concurrent.TimeUnit; public class SimpleAnimation { private int x = 70; private int y = 70; private int xPos = 70; private int yPos = 70; public static void main(String[] args) { SimpleAnimation gui = new SimpleAnimation(); Loading @@ -24,13 +24,13 @@ public class SimpleAnimation { frame.setVisible(true); for (int i = 0; i < 130; i++) { x++; y++; xPos++; yPos++; drawPanel.repaint(); try { Thread.sleep(50); TimeUnit.MILLISECONDS.sleep(50); } catch (Exception e) { e.printStackTrace(); } Loading @@ -40,7 +40,7 @@ public class SimpleAnimation { class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.green); g.fillOval(x, y, 40, 40); g.fillOval(xPos, yPos, 40, 40); } } } No newline at end of file src/main/java/ch14/TwoButtons.java +1 −1 Changes for src/main/java/ch14/TwoButtons.java: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ public class TwoButtons { colorButton.addActionListener(event -> frame.repaint()); label = new JLabel("I’m a label"); RandomColorPanel drawPanel = new RandomColorPanel(); MyDrawPanel drawPanel = new MyDrawPanel(); frame.getContentPane().add(BorderLayout.SOUTH, colorButton); frame.getContentPane().add(BorderLayout.CENTER, drawPanel); Loading Loading
src/main/java/ch14/MyDrawPanel.java +10 −2 Changes for src/main/java/ch14/MyDrawPanel.java: 10 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -2,13 +2,21 @@ package ch14; import javax.swing.*; import java.awt.*; import java.util.Random; class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.orange); g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.fillRect(20, 50, 100, 100); Random random = new Random(); int red = random.nextInt(256); int green = random.nextInt(256); int blue = random.nextInt(256); Color randomColor = new Color(red, green, blue); g.setColor(randomColor); g.fillOval(70, 70, 100, 100); } public static void main(String[] args) { Loading
src/main/java/ch14/SimpleAnimation.java +8 −8 Changes for src/main/java/ch14/SimpleAnimation.java: 8 added lines, 8 removed lines. Original line number Diff line number Diff line package ch14; import javax.swing.*; import java.awt.Color; import java.awt.Graphics; import java.awt.*; import java.util.concurrent.TimeUnit; public class SimpleAnimation { private int x = 70; private int y = 70; private int xPos = 70; private int yPos = 70; public static void main(String[] args) { SimpleAnimation gui = new SimpleAnimation(); Loading @@ -24,13 +24,13 @@ public class SimpleAnimation { frame.setVisible(true); for (int i = 0; i < 130; i++) { x++; y++; xPos++; yPos++; drawPanel.repaint(); try { Thread.sleep(50); TimeUnit.MILLISECONDS.sleep(50); } catch (Exception e) { e.printStackTrace(); } Loading @@ -40,7 +40,7 @@ public class SimpleAnimation { class MyDrawPanel extends JPanel { public void paintComponent(Graphics g) { g.setColor(Color.green); g.fillOval(x, y, 40, 40); g.fillOval(xPos, yPos, 40, 40); } } } No newline at end of file
src/main/java/ch14/TwoButtons.java +1 −1 Changes for src/main/java/ch14/TwoButtons.java: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -23,7 +23,7 @@ public class TwoButtons { colorButton.addActionListener(event -> frame.repaint()); label = new JLabel("I’m a label"); RandomColorPanel drawPanel = new RandomColorPanel(); MyDrawPanel drawPanel = new MyDrawPanel(); frame.getContentPane().add(BorderLayout.SOUTH, colorButton); frame.getContentPane().add(BorderLayout.CENTER, drawPanel); Loading