Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 345b9f6

Browse files
authoredFeb 17, 2020
Merge pull request #32 from xdvrx1/master
Patch: `setIconImage`
2 parents 7d453f1 + 91c4782 commit 345b9f6

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed
 
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package simplejavacalculator;
2+
3+
import java.io.*;
4+
import java.awt.image.BufferedImage;
5+
import javax.imageio.ImageIO;
6+
import java.awt.*;
7+
8+
/**
9+
*This class will return an image
10+
*from a binary data.
11+
*/
12+
class BufferedImageCustom {
13+
public Image imageReturn()
14+
throws IOException {
15+
Image image;
16+
17+
InputStream bis = getClass().getResourceAsStream("/icon/icon.png");
18+
BufferedImage bImage2 = ImageIO.read(bis);
19+
image = bImage2;
20+
21+
return image;
22+
}
23+
}

‎src/simplejavacalculator/SimpleJavaCalculator.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
package simplejavacalculator;
1818

1919
public class SimpleJavaCalculator {
20-
21-
public static void main(String[] args) {
22-
UI uiCal = new UI();
23-
uiCal.init();
24-
}
25-
20+
21+
public static void main(String[] args) {
22+
try {
23+
UI uiCal = new UI();
24+
uiCal.init();
25+
}
26+
catch (Exception e) {
27+
System.out.println(e.getMessage());
28+
}
29+
30+
}
2631
}

‎src/simplejavacalculator/UI.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
import java.awt.Font;
3030
import javax.swing.Box;
3131
import javax.swing.BoxLayout;
32-
import java.awt.Toolkit;
32+
3333
import java.awt.Image;
3434
import javax.swing.ImageIcon;
35+
import java.io.*;
3536

3637
public class UI implements ActionListener {
3738

@@ -58,12 +59,14 @@ public class UI implements ActionListener {
5859

5960
private final Font font;
6061
private final Font textFont;
61-
ImageIcon image;
62+
private ImageIcon image;
63+
private BufferedImageCustom imageReturn;
6264

63-
public UI() {
65+
public UI() throws IOException {
6466
frame = new JFrame("Calculator PH");
6567

66-
image = new ImageIcon("icon/icon.png");
68+
imageReturn = new BufferedImageCustom();
69+
image = new ImageIcon(imageReturn.imageReturn());
6770

6871
panel = new JPanel();
6972
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
@@ -114,6 +117,7 @@ public void init() {
114117
frame.setLocationRelativeTo(null);
115118
frame.setResizable(false);
116119
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
120+
117121
frame.setIconImage(image.getImage());
118122

119123
text.setFont(textFont);

0 commit comments

Comments
 (0)
Please sign in to comment.