blog containing information about IT

 

Changing the Application Icon In Java Swing


What is swing java?
Swing Java-based programming is one of the GUI (Graphical User Interface) in Java. Surely, there are two kinds of programming Java based GUI (Graphical User Interface), namely: AWT and Swing.
But in its development AWT is not recommended for use due to safety factors. Lots of features found in Swing, but on this occasion we will only replace the icon alone.
Although rarely used in Swing desktop application base, because most developers prefer to use VB, Delphi or. NET lighter and do not eat a lot of memory resources because it is native.
However, the use of cross-platform java can so we do not need to make an application twice.
  • Getting Started Coding
I certainly do not need to be reminded again, where you have to write a java program code and how to compile and execute.
Following code before the program icon replaced
/ / SebelumGanti.java

javax.swing.JFrame import;
javax.swing.SwingUtilities import;

 SebelumGanti class {
 private static void gantiIcon () {
   JFrame.setDefaultLookAndFeelDecorated (true);
   JFrame f = new JFrame ("Icon Terganti yet");
   f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
   f.setSize (400, 400);
   f.setVisible (true);
 }

 public static void main (String [] args) {
 SwingUtilities.invokeLater (new Runnable () {
   public void run () {
  gantiIcon ();
   }
  });
    }
 }
Following code to change the icon
/ / SesudahGanti.java
javax.swing.JFrame import;
javax.swing.ImageIcon import;
javax.swing.SwingUtilities import;
java.awt.Toolkit import;

SesudahGanti {public class
  private static void gantiIcon () {

/ / This makes the frame look the same on all operating systems
   JFrame.setDefaultLookAndFeelDecorated (true);

   / / Create frame objects with similar titles
   JFrame f = new JFrame ("Icon It Terganti");

   / / The first way to change the icon on the swing
   ImageIcon image = new ImageIcon ("bomb.png");
   f.setIconImage (gambar.getImage ());

   / / The second way to change the icon on the swing
   f.setIconImage (Toolkit.getDefaultToolkit (). getImage ("bomb.png"));
   f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
   f.setSize (400, 400);
   f.setVisible (true);
 }

  public static void main (String [] args) {
 / / Swing application is placed in a different thread
 SwingUtilities.invokeLater (new Runnable () {
   public void run () {
  gantiIcon ();
   }});
 }
  }
Such is a brief tutorial on using java desktop application. May be useful and helpful to those of you who are learning java programming. We met again in an upcoming issue.


Read more: http://blog.fastncheap.com/merubah-icon-pada-aplikasi-swing-java/#ixzz2PY21MZU4

Comments :

0 comments to “Changing the Application Icon In Java Swing”

Post a Comment

Categories

Recent Post

Guest book

Stats

Flag Counter

Enter your email address:

Delivered by FeedBurner

 
Sainstex
Blogger Template by Sainstex Share In Premium Themes Blogger | Host In Blogger.com