Hi,
im testing a simple code for an ActionLIstener event for a button.
the expected outcome with the functionality of the button is ok.
but i couldn't set the *theme* get displayed.
i.e. the method calling lookAndFeel() does not seems to work.
any help would be greately appreciable.
thank you very much
[FONT=Courier, Monospaced]import java.awt.*; import java.awt.event.*; import javax.swing.SwingUtilities; import javax.swing.UIManager; [/FONT] [FONT=Courier, Monospaced]public class AL extends Frame implements WindowListener,ActionListener { [/FONT] [FONT=Courier, Monospaced] TextField text = new TextField(20); Button b; private int numClicks = 0; [/FONT] [FONT=Courier, Monospaced] public static void main(String[] args) { [/FONT] [FONT=Courier, Monospaced] AL myWindow = new AL("My first window"); myWindow.setSize(350,100); myWindow.setVisible(true); } [/FONT] [FONT=Courier, Monospaced] public AL(String title) { [/FONT] [FONT=Courier, Monospaced] super(title); setLayout(new FlowLayout()); addWindowListener(this); lookAndFeel(); [/FONT] [FONT=Courier, Monospaced] b = new Button("Click me"); add(b); add(text); b.addActionListener(this); } [/FONT] [FONT=Courier, Monospaced] public void lookAndFeel(){ try{ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(this); }catch(Exception e){ System.out.println("errr"); } } [/FONT] [FONT=Courier, Monospaced] public void actionPerformed(ActionEvent e) { numClicks++; text.setText("Button Clicked " + numClicks + " times"); [/FONT] [FONT=Courier, Monospaced] } [/FONT] [FONT=Courier, Monospaced] public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } [/FONT] [FONT=Courier, Monospaced] public void windowOpened(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} [/FONT]
i heard that lookandfeel() cannot be applied to JFrame. but for the below program the lookandfeel() works well.
[FONT=Courier, Monospaced]import javax.swing.*; import java.awt.*; /** * * @author arshad */ public class ProgressMonitor extends JFrame{ [/FONT] [FONT=Courier, Monospaced] JProgressBar current; JTextArea out; JButton find; Thread runner; int num=0; [/FONT] [FONT=Courier, Monospaced] public ProgressMonitor() { [/FONT] [FONT=Courier, Monospaced] super("Progress Monitor"); Dimension d=java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setSize(d); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLookAndFeel(); [/FONT] [FONT=Courier, Monospaced]// setSize(205,68); setLayout(new FlowLayout()); current=new JProgressBar(0,2000); current.setValue(0); current.setStringPainted(true); JLabel label=new JLabel("You have been fooled!, Your machine is being formatted"); JPanel panel=new JPanel(); [/FONT] [FONT=Courier, Monospaced]// panel.add(sld); [/FONT] [FONT=Courier, Monospaced] panel.add(label); panel.add(current); add(panel); setVisible(true); ///add(current); [/FONT] [FONT=Courier, Monospaced]// pack(); [/FONT] [FONT=Courier, Monospaced] } [/FONT] [FONT=Courier, Monospaced] private void setLookAndFeel(){ try{ [/FONT] [FONT=Courier, Monospaced]UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.updateComponentTreeUI(this); }catch(Exception e){ System.out.println("errorrrr"); } } [/FONT] [FONT=Courier, Monospaced] public void iterate(){ while(num<2000){ current.setValue(num); try{ Thread.sleep(1000); }catch(InterruptedException e){} num+=95; [/FONT] [FONT=Courier, Monospaced] } [/FONT] [FONT=Courier, Monospaced] } [/FONT] [FONT=Courier, Monospaced]public static void main(String arg[]){ ProgressMonitor frame=new ProgressMonitor(); frame.setVisible(true); frame.iterate(); [/FONT]