fala
Jefferson, blz?????
O erro
que estava acontecendo é que vc comparava o evento do botão com uma String, o
que resultava que ele nunca entrava no evento para setar a
strPlat...
vc faz
assim ..... if (objSource == "Metal") e o jeito certo é vc comparar com o objeto
JButton..... if (objSource == btnMetal).....
outra
coisa, debugue mais o código e coloque System.out no catch para vc ver que erro
está dando, pois ele dava ClassNotFoundException, por justamente não achar a
classe pq não era setada a strPlat.....
segue
o código com as alterações abaixo...... espero ter
ajudado.....
Falow!!!
import java.awt.*;
import java.awt.event.*; import javax.swing.*; class panPlat extends JPanel implements ActionListener { public panPlat() { btnMetal = new JButton("Metal"); btnMotif = new JButton("Motif"); btnWindows = new JButton("Windows");
add(btnMetal);
add(btnMotif); add(btnWindows);
btnMetal.addActionListener(this);
btnMotif.addActionListener(this); btnWindows.addActionListener(this); } public void
actionPerformed(ActionEvent evt)
{ Object objSource = evt.getSource(); String strPlat = ""; if (objSource == btnMetal)
{ strPlat = "javax.swing.plaf.metal.MetalLookAndFeel"; }
if (objSource == btnMotif)
{ strPlat = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; }
if (objSource == btnWindows)
{ strPlat = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; }
try
{ UIManager.setLookAndFeel(strPlat); SwingUtilities.updateComponentTreeUI(this); }
catch (Exception
e)
{ System.out.println("Erro = " + e); } } private JButton
btnMetal;
private JButton btnMotif; private JButton btnWindows; } class frmPlat extends
JFrame
{ public
frmPlat()
{ setTitle("Muda Visual do Java"); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); setSize((d.width/4), (d.height/4)); setLocation((d.width/4), (d.height/4));
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e) { System.exit(0); } }); Container
con = getContentPane();
con.add(new panPlat()); } } import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TrocaPlataforma { public static void main(String args[]) { JFrame frame = new frmPlat(); frame.show(); } } []'s
Thiago
|