Hey, I'm fairly new to java, been reading sams teach yourself java 6 in 21 days.
I ran into an error with a code in the day 12 section.
import java.awt.event.*; import javax.swing.*; import java.awt.*; [COLOR="DarkRed"]public class TitleChanger extends JFrame implements ActionListener[/COLOR] { JButton b1 = new JButton("Rosencrantz"); JButton b2 = new JButton("Guildenstern"); public TitleChanger() { super("Title Bar"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); b1.addActionListener(this); b2.addActionListener(this); FlowLayout flow = new FlowLayout(); setLayout(flow); add(b1); add(b2); pack(); setVisible(true); } public void actionPreformed(ActionEvent evt) { Object source = evt.getSource(); if (source == b1) { setTitle("Rosencrantz"); } else if (source == b2) { setTitle("Guildenstern"); } repaint(); } public static void main(String[] arguments) { TitleChanger frame = new TitleChanger(); } }
Now whenever i try to compile this, it will say that TitleChanger is not abstract and cannot override abstract method actionPreformed(java.awt.event.ActionEvent).
After i declare the main class as abstract however.
import java.awt.event.*; import javax.swing.*; import java.awt.*; public abstract class TitleChanger extends JFrame implements ActionListener { JButton b1 = new JButton("Rosencrantz"); JButton b2 = new JButton("Guildenstern"); public TitleChanger() { super("Title Bar"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); b1.addActionListener(this); b2.addActionListener(this); FlowLayout flow = new FlowLayout(); setLayout(flow); add(b1); add(b2); pack(); setVisible(true); } public void actionPreformed(ActionEvent evt) { Object source = evt.getSource(); if (source == b1) { setTitle("Rosencrantz"); } else if (source == b2) { setTitle("Guildenstern"); } repaint(); } public static void main(String[] arguments) { [COLOR="DarkRed"]TitleChanger frame = new TitleChanger();[/COLOR] } }
The compiler will say that TitleChanger is abstract; cannot be instantiated.
TitleChanger frame = new TitleChanger();
I am currently using Windows Vista, and was wondering if anyone might have a solution, or be able to point me to another source.