Okay. So what I was supposed to be doing was "Designing and implementing a program that displays a numeric keypad that may appear on a phone. Above the keypad buttons, show a label that displays the numbers as they are picked. To the right of the keypad buttons, include another button to clear the display. Use a border layout to manage the overall presentation, and a grid layout to manage the keypad buttons. Put a border around the keypad buttons to group them visually, and a border around the display."
This is the code:
When I try to compile with jGrasp I get this error:Code:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.BorderFactory.*;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
public class PhoneKeys extends JFrame implements ActionListener {
JFrame window = new JFrame();//frame to hold the panels
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
JButton b6 = new JButton("6");
JButton b7 = new JButton("7");
JButton b8 = new JButton("8");
JButton b9 = new JButton("9");
JButton bStar = new JButton("*");
JButton b0 = new JButton("0");
JButton bPound = new JButton("#");
JButton bClear = new JButton("clear");
JTextField tf = new JTextField();
// pressed
private Border lineBorder = new LineBorder(Color.BLACK, 2);
PhoneKeys() {
window.setSize(300,300);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(new BorderLayout());
// keypad panel
JPanel keypad = new JPanel(new GridLayout(4, 3));
// create buttons, with ActionListener
keypad.setBorder(lineBorder);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
bStar.addActionListener(this);
bPound.addActionListener(this);
// add buttons to panel
keypad.add(b1);
keypad.add(b2);
keypad.add(b3);
keypad.add(b4);
keypad.add(b5);
keypad.add(b6);
keypad.add(b7);
keypad.add(b8);
keypad.add(b9);
keypad.add(bStar);
keypad.add(b0);
keypad.add(bPound);
// create a "clear" button to clear the displayed number
JPanel clear = new JPanel();
bClear.addActionListener(this);
clear.add(bClear);
// panel that displays the number of the button pressed
JPanel display = new JPanel();
JLabel lab = new JLabel();
lab.add(tf);
display.add(lab);
window.add(display, BorderLayout.NORTH);
window.add(keypad, BorderLayout.WEST);
window.add(clear, BorderLayout.EAST);
window.setVisible(true);
}
Could anyone help me with this situation? What am i doing wrong?Quote:
PhoneKeys.java:97: error: reached end of file while parsing
