File tree Expand file tree Collapse file tree 3 files changed +42
-10
lines changed
Expand file tree Collapse file tree 3 files changed +42
-10
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1717package simplejavacalculator ;
1818
1919public 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}
Original file line number Diff line number Diff line change 2929import java .awt .Font ;
3030import javax .swing .Box ;
3131import javax .swing .BoxLayout ;
32- import java . awt . Toolkit ;
32+
3333import java .awt .Image ;
3434import javax .swing .ImageIcon ;
35+ import java .io .*;
3536
3637public 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 );
You can’t perform that action at this time.
0 commit comments