my gui class:
import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JPasswordField; import javax.swing.JOptionPane; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame{ private JTextField tf; private Font pf; private Font bf; private Font itf; private Font biff; private JRadioButton pb; private JRadioButton bb; private JRadioButton ib; private JRadioButton bib; private ButtonGroup group; public GUI(){ super("The Title"); setLayout(new FlowLayout()); tf= new JTextField("Nikolai is awesome", 25); add(tf); pb=new JRadioButton("plain", true); bb=new JRadioButton("bold", false); ib=new JRadioButton("italic", false); bib=new JRadioButton("bold and italic", false); add(pb); add(bb); add(ib); add(bib); group=new ButtonGroup(); group.add(pb); group.add(bb); group.add(ib); group.add(bib); pf=new Font("Serif", Font.PLAIN, 14); bf=new Font("Serif", Font.BOLD, 14); itf=new Font("Serif", Font.ITALIC, 14); biff=new Font("Serif", Font.BOLD + Font.ITALIC, 14); tf=setFont(pf);//<--this is the line reference for GUI line 58 pb.addItemListener(new HandlerClass(pf)); bb.addItemListener(new HandlerClass(bf)); ib.addItemListener(new HandlerClass(itf)); bib.addItemListener(new HandlerClass(biff)); } private class HandlerClass implements ItemListener{ private Font font; public HandlerClass(Font f){ font=f; } public void itemStateChanged(ItemEvent event){ tf.setFont(font); } } }
eclipse error message:Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from void to JTextField at GUI.<init>(GUI.java:58) at Apples.main(Apples.java:7)
A fix and explanation would be much appreciated. I copied this from a thenewboston tutorial and he uses an old version of java but im pretty sure ive copied character for character!