在java 中由三种界面样式
Metal是默认的样式 个平台运行一致
Windows 是在windows中的样式
Motif
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class plafPanel extends JPanel implements ActionListener
{
public plafPanel()
{
metalButton=new JButton("Metal");
motifButton=new JButton("Motif");
windowsButton=new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object source=evt.getSource();
String plaf="";
if (source==metalButton)
plaf="javax.swing.plaf.metal.MetalLookAndFell";
else if (source==motifButton)
plaf="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source==windowsButton)
plaf="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
{
//diao yong UIManager.setLookAndFeel() method and SwingUtilities.updateComponetTree() methoe;
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception e){}
}
private JButton metalButton;
private JButton motifButton;
private JButton windowsButton;
}
class plafFrame extends JFrame
{
public plafFrame()
{
setTitle("plafTest");
setSize(300,300);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane=getContentPane();
contentPane.add(new plafPanel());
}
}
public class PlafTest
{
public static void main(String args[])
{
JFrame test=new plafFrame();
test.setVisible(true);
}
}
Metal是默认的样式 个平台运行一致
Windows 是在windows中的样式
Motif
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class plafPanel extends JPanel implements ActionListener
{
public plafPanel()
{
metalButton=new JButton("Metal");
motifButton=new JButton("Motif");
windowsButton=new JButton("Windows");
add(metalButton);
add(motifButton);
add(windowsButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object source=evt.getSource();
String plaf="";
if (source==metalButton)
plaf="javax.swing.plaf.metal.MetalLookAndFell";
else if (source==motifButton)
plaf="com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source==windowsButton)
plaf="com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
{
//diao yong UIManager.setLookAndFeel() method and SwingUtilities.updateComponetTree() methoe;
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
}
catch(Exception e){}
}
private JButton metalButton;
private JButton motifButton;
private JButton windowsButton;
}
class plafFrame extends JFrame
{
public plafFrame()
{
setTitle("plafTest");
setSize(300,300);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
Container contentPane=getContentPane();
contentPane.add(new plafPanel());
}
}
public class PlafTest
{
public static void main(String args[])
{
JFrame test=new plafFrame();
test.setVisible(true);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货