Thursday, January 20, 2011

How to make JInternalFrame in Java

In this chapter we will make user interface in java with JInternalFrame component. JInternalFrame is a part from library java (import javax.swing.*). All component in java is using JFrame component to display to user, so we will make JFrame first. This is the hierarchy to using JInternalFrame in java.


1. Make the class with name "ExerciseUI.java".
2. Please follow source code bellow:


import javax.swing.*;

public class ExerciseUI {

private JFrame _frame = new JFrame();
private JInternalFrame _internalframe=new JInternalFrame();
private JDesktopPane _pane=new JDesktopPane();

public ExerciseUI() {
//Set property of JFrame component
_frame.setVisible(true);
_frame.setTitle("Exercise User Interface");
_frame.setExtendedState(_frame.MAXIMIZED_BOTH);
_frame.setDefaultCloseOperation(_frame.EXIT_ON_CLOSE);

//Set property of JIntenalFrame component
_internalframe.setTitle("I'm in Frame Bro!!! Hahahaha");
_internalframe.setSize(500,500);
_internalframe.setVisible(true);

//Add JInternalFrame component to JDesktopPane component
_pane.add(_internalframe);

//Add JDesktopPane component to JFrame component
_frame.add(_pane);
}
public static void main(String[] args) {
new ExerciseUI();
}
}

Note :
1. At line 3 is library user interface that provided by java .
2. At line 7 is make object JFrame with name "_frame".
3. At line 8 is make object JInternalFrame with name "_internalframe".
4. At line 9 is make object JDesktopPane with name "_pane".
5. At line 13-16 is set property of JFrame.
6. At line 19-21 is set property of JInternal Frame.
7. At line 24 is add JInternalFrame to JDesktopPane.
8. At line 27 is add JDesktopPane to JFrame.
9. At line 29-31 is use to running the class.

Congratulation you have successfully created JInternalFrame component in java. Thank for see this blog if there is have mistake please revision from you..^^

No comments:

Post a Comment