import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;
public class GUINew extends JDialog implements ActionListener
{
public static void main (String [] args)
{
protected JButton ok;
protected JButton cancel;
protected ButtonGroup type;
protected JTextField bid;
protected JTextField name;
int theBid;
String theName;
String theType;
public GUINew(String sTitle, JFrame owner) {
super (owner, sTitle, true);
setLooknFeel();
bid = new JTextField(4);
name = new JTextField(14);
ok = new JButton("Hire Boat!");
ok.addActionListener(this);
cancel = new JButton("Cancel");
cancel.addActionListener(this);
type = new ButtonGroup();
// create each radio button, specifying its label
JRadioButton pedal = new JRadioButton("Pedal boat");
JRadioButton rowing = new JRadioButton("Rowing boat");
// set a String to associate with each button
// will use this when the radio button is selected
pedal.setActionCommand("Pedal boat");
rowing.setActionCommand("Rowing boat");
type.add(pedal);
type.add(rowing);
JPanel top = new JPanel();
top.add(pedal);
top.add(rowing);
getContentPane().add("North", top);
JPanel center = new JPanel();
center.add(new JLabel("Enter Boat ID:"));
center.add(bid);
center.add(new JLabel("Enter Name/Colour:"));
center.add(name);
getContentPane().add("Center", center);
JPanel bottom = new JPanel();
bottom.add(ok);
bottom.add(cancel);
getContentPane().add("South", bottom);
pack();
}
public int getBid() { return theBid; }
public String getName() { return theName; }
public String getType() { return theType; }
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok)
{
theType = type.getSelection().getActionCommand();
// use the entered data
theBid = Integer.parseInt(bid.getText());
theName = name.getText();
}
else if (e.getSource() == cancel) {
this.dispose(); //will release memory
this.setVisible(false); //will hide the window
}
dispose();
}
// windows look and feel settings
protected void setLooknFeel()
{
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try
{
UIManager.setLookAndFeel(lookAndFeel);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
Error message java:17: illegal start of expression
protected JButton ok;
^
How do i get rid of this error message i have tried to get rid of the protected but more errors occure
and also how do i get the above prgram to work of this program
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Hire extends JDialog implements ActionListener
{
public stimatic void main (String [] args)
{
protected JButton ok;
protected JButton cancel;
protected JTextField bid;
protected JTextField name;
protected JTextField time;
protected BoatHireCompany theBoat;
public Hire(String sTitle, JFrame owner) {
super (owner, sTitle, true);
setLayout(new FlowLayout());
setSize(350,200);
add (new JLabel("Enter Boat ID:"));
bid = new JTextField(20);
add (bid);
add (new JLabel("Enter Customer Name:"));
name = new JTextField(20);
add (name);
add (new JLabel("Enter Current Time:"));
time = new JTextField(20);
add (time);
ok = new JButton("Hire Boat!");
ok.addActionListener(this);
add(ok);
cancel = new JButton("Cancel");
cancel.addActionListener(this);
add(cancel);
}
public BoatHireCompany getBoat()
{
return theBoat;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ok) {
theBoat = new BoatHireCompany(bid.getText(), name.getText(), time.getText());
}
else if (e.getSource() == cancel) {
// data entry cancelled
theBoat = null;
}
dispose();
}
}