slimestio
Network Pentester
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
This tutorial will teach you how to create a program that can choose and change the User Interface(UI) that is installed already in java.
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of UILookAndFeel.java.
2. Import the following package library:
3. Initialize the following variable components in your Main.
4. To have an event for changing the UI of the frame, we will use the ActionListener and when clicking a particular component it will change the UI directly.
To get all the installed User Interface in java, have this code below:
5. Now, create a JButton component in which it will get all the installed UI in your java software. This will also call the ActionListener that we have declared above when clicking the button.
6. Lastly, add all the components, set the layout into GridLayout, set the size, visibility, and the close operation of the frame. Have this code below:
Output:
Here's the full code of this tutorial:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
So, now let's start this tutorial!
1. Open JCreator or NetBeans and make a java program with a file name of UILookAndFeel.java.
2. Import the following package library:
- import
java.awt.event.*
;
//used to access the ActionEvent and ActionListener class
- import
java.awt.*
;
//used to access the GridLayout class
- import
javax.swing.*
;
//used to access the JButton,JList,JTextArea,JFrame,JPanel,SwingUtilities and UIManager class
3. Initialize the following variable components in your Main.
- final
JFrame
frame =
new
JFrame
(
"Change User Interface"
)
;
- JList
comboBox =
new
JList
(
new
String
[
]
{
"www.sourcecodester.com"
, "This is a List."
}
)
;
- JTextArea
txtArea =
new
JTextArea
(
"www.facebook.com/BermzISware \n
This is a TextArea."
)
;
- JPanel
panel =
new
JPanel
(
)
;
4. To have an event for changing the UI of the frame, we will use the ActionListener and when clicking a particular component it will change the UI directly.
- ActionListener
changeUI =
new
ActionListener
(
)
{
- public
void
actionPerformed(
ActionEvent
actionEvent)
{
- String
plaf =
null
;
- plaf =
actionEvent.getActionCommand
(
)
;
- String
finalLafClassName =
plaf;
- try
{
- UIManager
.setLookAndFeel
(
finalLafClassName)
;
- SwingUtilities
.updateComponentTreeUI
(
frame)
;
- }
catch
(
Exception
exception)
{
- System
.out
.print
(
"Can't change look and feel."
)
;
- }
- }
- }
;
To get all the installed User Interface in java, have this code below:
- UIManager.LookAndFeelInfo
UIlooks[
]
=
UIManager
.getInstalledLookAndFeels
(
)
;
5. Now, create a JButton component in which it will get all the installed UI in your java software. This will also call the ActionListener that we have declared above when clicking the button.
- for
(
int
i =
0
, n =
UIlooks.length
;
i <
n;
i++
)
{
- JButton
button =
new
JButton
(
UIlooks[
i]
.getName
(
)
)
;
- button.setActionCommand
(
UIlooks[
i]
.getClassName
(
)
)
;
- button.addActionListener
(
changeUI)
;
- panel.add
(
button)
;
- }
6. Lastly, add all the components, set the layout into GridLayout, set the size, visibility, and the close operation of the frame. Have this code below:
- frame.getContentPane
(
)
.setLayout
(
new
GridLayout
(
1
,1
)
)
;
- frame.getContentPane
(
)
.add
(
comboBox)
;
- frame.getContentPane
(
)
.add
(
txtArea)
;
- frame.getContentPane
(
)
.add
(
panel)
;
- frame.setSize
(
580
, 250
)
;
- frame.setVisible
(
true
)
;
- frame.setDefaultCloseOperation
(
JFrame
.EXIT_ON_CLOSE
)
;
Output:

Here's the full code of this tutorial:
- import
java.awt.event.*
;
//used to access the ActionEvent and ActionListener class
- import
java.awt.*
;
//used to access the GridLayout class
- import
javax.swing.*
;
//used to access the JButton,JList,JTextArea,JFrame,JPanel,SwingUtilities and UIManager class
- public
class
UILookAndFeel {
- public
static
void
main(
String
args[
]
)
{
- final
JFrame
frame =
new
JFrame
(
"Change User Interface"
)
;
- JList
comboBox =
new
JList
(
new
String
[
]
{
"www.sourcecodester.com"
, "This is a List."
}
)
;
- JTextArea
txtArea =
new
JTextArea
(
"www.facebook.com/BermzISware \n
This is a TextArea."
)
;
- JPanel
panel =
new
JPanel
(
)
;
- ActionListener
changeUI =
new
ActionListener
(
)
{
- public
void
actionPerformed(
ActionEvent
actionEvent)
{
- String
plaf =
null
;
- plaf =
actionEvent.getActionCommand
(
)
;
- String
finalLafClassName =
plaf;
- try
{
- UIManager
.setLookAndFeel
(
finalLafClassName)
;
- SwingUtilities
.updateComponentTreeUI
(
frame)
;
- }
catch
(
Exception
exception)
{
- System
.out
.print
(
"Can't change look and feel."
)
;
- }
- }
- }
;
- UIManager.LookAndFeelInfo
UIlooks[
]
=
UIManager
.getInstalledLookAndFeels
(
)
;
- for
(
int
i =
0
, n =
UIlooks.length
;
i <
n;
i++
)
{
- JButton
button =
new
JButton
(
UIlooks[
i]
.getName
(
)
)
;
- button.setActionCommand
(
UIlooks[
i]
.getClassName
(
)
)
;
- button.addActionListener
(
changeUI)
;
- panel.add
(
button)
;
- }
- frame.getContentPane
(
)
.setLayout
(
new
GridLayout
(
1
,1
)
)
;
- frame.getContentPane
(
)
.add
(
comboBox)
;
- frame.getContentPane
(
)
.add
(
txtArea)
;
- frame.getContentPane
(
)
.add
(
panel)
;
- frame.setSize
(
580
, 250
)
;
- frame.setVisible
(
true
)
;
- frame.setDefaultCloseOperation
(
JFrame
.EXIT_ON_CLOSE
)
;
- }
- }
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
You must upgrade your account or reply in the thread to view hidden text.