RSS

coding java lookandfeel

04 May

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager;

public class demo extends JFrame {
JButton jButton1=new JButton(“Demo LookAndFeel”);
JButton jButton2=new JButton(“Ini Adalah Contoh Demo LookAndFeel Aje Bro…!!!!”);
JButton jButton3=new JButton(“Close”);
Object obj[]={“Pilih LookAndFeel”,”Style Xp”,”Style Window”,”Style Classic Window”,”Style Motif”};
JComboBox jComboBox=new JComboBox(obj);
JPanel jPanelComboBox=new JPanel(new FlowLayout(FlowLayout.RIGHT));
JPanel jPanelFlow=new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel jPanelButton=new JPanel(new GridLayout(3,1));
JPanel jPanelSeting=new JPanel(new BorderLayout());
Font font=new Font(“Arial”,Font.PLAIN,12);
Font font0=new Font(“Arial”,Font.ITALIC,16);
Font font1=new Font(“Arial”,Font.BOLD,20);
public demo(){
demo_lookandfeel();
}
public void demo_lookandfeel(){
jPanelButton.add(jButton1);
jPanelButton.add(jButton2);
jPanelButton.add(jButton3);
jPanelComboBox.add(jComboBox);
jPanelComboBox.add(jPanelButton);
panel_seting();
}
public void panel_seting(){
jPanelSeting.add(jPanelButton);
jPanelSeting.add(jPanelButton,BorderLayout.NORTH);
jPanelSeting.add(jPanelComboBox,BorderLayout.SOUTH);
setContentPane(jPanelSeting);
setSize(650,350);
setLocation(80,20);
setVisible(true);
hendel();
}
public void hendel(){
jButton3.addActionListener(new button_hendel());
jComboBox.addActionListener(new combobox_hendel());
}
class combobox_hendel implements ActionListener{
public void actionPerformed(ActionEvent e){
if(jComboBox.getSelectedItem().equals(“Style Xp”)){
try{
UIManager.setLookAndFeel(“javax.swing.plaf.metal.MetalLookAndFeel”);
SwingUtilities.updateComponentTreeUI(demo.this);
}catch(Exception ex){
}
}else if(jComboBox.getSelectedItem().equals(“Style Window”)){
try{
jButton1.setFont(font);
jButton2.setFont(font);
jButton3.setFont(font);
jComboBox.setFont(font);
UIManager.setLookAndFeel(“com.sun.java.swing.plaf.windows.WindowsLookAndFeel”);
SwingUtilities.updateComponentTreeUI(demo.this);
}catch(Exception ex){
}
}else if(jComboBox.getSelectedItem().equals(“Style Classic Window”)){
try{
jButton1.setFont(font0);
jButton2.setFont(font0);
jButton3.setFont(font0);
jComboBox.setFont(font0);
UIManager.setLookAndFeel(“com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel”);
SwingUtilities.updateComponentTreeUI(demo.this);
}catch(Exception ex){
}
}else if(jComboBox.getSelectedItem().equals(“Style Motif”)){
try{
jButton1.setFont(font1);
jButton2.setFont(font1);
jButton3.setFont(font1);
jComboBox.setFont(font1);
UIManager.setLookAndFeel(“com.sun.java.swing.plaf.motif.MotifLookAndFeel”);
SwingUtilities.updateComponentTreeUI(demo.this);
}catch(Exception ex){
}
}
}
}
class button_hendel implements ActionListener{
public void actionPerformed(ActionEvent e){
System.exit(0);
}
}
public static void main(String[]bangke_tonk_zampah){
new demo();
}
}

 
Leave a comment

Posted by on May 4, 2011 in about me

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: