Skip to content

Commit

Permalink
Merge pull request #32 from xdvrx1/master
Browse files Browse the repository at this point in the history
Patch: `setIconImage`
  • Loading branch information
pH-7 authored Feb 17, 2020
2 parents 7d453f1 + 91c4782 commit 345b9f6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
23 changes: 23 additions & 0 deletions src/simplejavacalculator/BufferedImageCustom.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 11 additions & 6 deletions src/simplejavacalculator/SimpleJavaCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
}
12 changes: 8 additions & 4 deletions src/simplejavacalculator/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 345b9f6

Please sign in to comment.