diff --git a/src/simplejavacalculator/BufferedImageCustom.java b/src/simplejavacalculator/BufferedImageCustom.java new file mode 100644 index 0000000..196f440 --- /dev/null +++ b/src/simplejavacalculator/BufferedImageCustom.java @@ -0,0 +1,23 @@ +package simplejavacalculator; + +import java.io.*; +import java.awt.image.BufferedImage; +import javax.imageio.ImageIO; +import java.awt.*; + +/** + *This class will return an image + *from a binary data. + */ +class BufferedImageCustom { + public Image imageReturn() + throws IOException { + Image image; + + InputStream bis = getClass().getResourceAsStream("/icon/icon.png"); + BufferedImage bImage2 = ImageIO.read(bis); + image = bImage2; + + return image; + } +} diff --git a/src/simplejavacalculator/SimpleJavaCalculator.java b/src/simplejavacalculator/SimpleJavaCalculator.java index 238603c..cd11787 100644 --- a/src/simplejavacalculator/SimpleJavaCalculator.java +++ b/src/simplejavacalculator/SimpleJavaCalculator.java @@ -17,10 +17,15 @@ package simplejavacalculator; public class SimpleJavaCalculator { - - public static void main(String[] args) { - UI uiCal = new UI(); - uiCal.init(); - } - + + public static void main(String[] args) { + try { + UI uiCal = new UI(); + uiCal.init(); + } + catch (Exception e) { + System.out.println(e.getMessage()); + } + + } } diff --git a/src/simplejavacalculator/UI.java b/src/simplejavacalculator/UI.java index b7a2633..f207e9a 100644 --- a/src/simplejavacalculator/UI.java +++ b/src/simplejavacalculator/UI.java @@ -29,9 +29,10 @@ import java.awt.Font; import javax.swing.Box; import javax.swing.BoxLayout; -import java.awt.Toolkit; + import java.awt.Image; import javax.swing.ImageIcon; +import java.io.*; public class UI implements ActionListener { @@ -58,12 +59,14 @@ public class UI implements ActionListener { private final Font font; private final Font textFont; - ImageIcon image; + private ImageIcon image; + private BufferedImageCustom imageReturn; - public UI() { + public UI() throws IOException { frame = new JFrame("Calculator PH"); - image = new ImageIcon("icon/icon.png"); + imageReturn = new BufferedImageCustom(); + image = new ImageIcon(imageReturn.imageReturn()); panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); @@ -114,6 +117,7 @@ public void init() { frame.setLocationRelativeTo(null); frame.setResizable(false); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setIconImage(image.getImage()); text.setFont(textFont);