Hi, Khách!
![]() | ![]() ![]() ![]() ![]() |
Bài 20 - Cách sử dụng LaF của hãng thứ 3:
Cách 1: coi nó như là 1 add-in plugin, tức là đưa cái file .jar chứa class mình cần vào thư mục jdk1.5.0\jre\lib\ext rồi cứ thế điều chỉnh className cho phù hợp
Cách 2: giải nén file .jar ra và tống thẳng nó vào gói jdk1.5.0\jre\lib\rt.jar
Ví dụ: bạn DOWN được gói xplookandfeel.jar và chép nó theo cách 1
Bạn hãy mở file readme của gói này ra và tìm thấy className của nó là "com.stefankrause.xplookandfeel.XPLookAndFeel" thì đưa thêm nó vào
* LaF có bản quyền (ở đây lấy ví dụ là Alloy-có cả mã)
Để sử dụng LaF có bản quyền bạn setProperty cho nó, ví dụ là dùng AlloyLaF (className là "com.incors.plaf.alloy.AlloyLookAndFeel")
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Core
{
public static void main(String args[)
{
com.incors.plaf.alloy.AlloyLookAndFeel.setProperty("alloy.licenseCode","v#ej_technologies#uwbjzx#e6pck8");
final JFrame f = new JFrame("My f");
final String[ a={"Metal","Windows","Motif","XP","Alloy"};
final Checkbox[ b=new Checkbox[a.length;
final String[ c=new String[a.length;
CheckboxGroup g=new CheckboxGroup();
c[0="javax.swing.plaf.metal.MetalLookAndFeel";
c[1="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
c[2="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
c[3="com.stefankrause.xplookandfeel.XPLookAndFeel";
c[4="com.incors.plaf.alloy.AlloyLookAndFeel";
Panel p=new Panel();
f.add(p);
for(int i=0;i<a.length;i++)
{
b[i=new Checkbox(a[i,g,false);
p.add(b[i);
b[i.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
for(int j=0;j<a.length;j++)
{
if(e.getSource()==b[j)
{
try
{
UIManager.setLookAndFeel(c[j);
}
catch(Exception exception)
{
System.out.println("LaF not found");
}
SwingUtilities.updateComponentTreeUI(f);
}
}
}
});
}
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
Copy code
import java.awt.*;
import java.awt.event.*;
class Core
{
public static void main(String args[)
{
com.incors.plaf.alloy.AlloyLookAndFeel.setProperty("alloy.licenseCode","v#ej_technologies#uwbjzx#e6pck8");
final JFrame f = new JFrame("My f");
final String[ a={"Metal","Windows","Motif","XP","Alloy"};
final Checkbox[ b=new Checkbox[a.length;
final String[ c=new String[a.length;
CheckboxGroup g=new CheckboxGroup();
c[0="javax.swing.plaf.metal.MetalLookAndFeel";
c[1="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
c[2="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
c[3="com.stefankrause.xplookandfeel.XPLookAndFeel";
c[4="com.incors.plaf.alloy.AlloyLookAndFeel";
Panel p=new Panel();
f.add(p);
for(int i=0;i<a.length;i++)
{
b[i=new Checkbox(a[i,g,false);
p.add(b[i);
b[i.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
for(int j=0;j<a.length;j++)
{
if(e.getSource()==b[j)
{
try
{
UIManager.setLookAndFeel(c[j);
}
catch(Exception exception)
{
System.out.println("LaF not found");
}
SwingUtilities.updateComponentTreeUI(f);
}
}
}
});
}
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
Copy code

Trực Tuyến:
Khách: 1