import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import javax.swing.*;
public class Telephone {
public Telephone()
{
JPanel speakerPanel = new JPanel(); // creats the speakerPanel
speakerPanel.setLayout(new BorderLayout()); // sets the layout for the speakerPanel
speakerPanel.add(new JLabel("Speaker:"), BorderLayout.NORTH);
JTextArea speakerField = new JTextArea(10, 25);
speakerField.add(speakerField, BorderLayout.CENTER);
String keyLabels = "123456789*0#";
JPanel keyPanel = new JPanel();
keyPanel.setLayout(new GridLayout(4, 3));
for(int i=0; i< keyLabels.length(); i++)
{
final String label = keyLabels.substring(i, i+1);
JButton keyButton = new JButton(label);
keyPanel.add(keyButton);
keyButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
connect.dial(label);
}
});
}
final JTextArea microphoneField = new JTextArea(10, 25);
JButton speechButton = new JButton("Send Speech");
speechButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
connect.record(microphoneField.getText());
microphoneField.setText("");
}
});
JButton hangupButton = new JButton("hangup");
hangupButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
connect.hangup();
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.add(speechButton);
buttonPanel.add(hangupButton);
JPanel microphonePanel = new JPanel();
microphonePanel.setLayout(new BorderLayout());
microphonePanel.add(new JLabel("Microphone:"), BorderLayout.NORTH);
microphonePanel.add(microphoneField, BorderLayout.CENTER);
microphonePanel.add(buttonPanel, BorderLayout.SOUTH);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(speakerPanel, BorderLayout.NORTH);
frame.add(keyPanel, BorderLayout.CENTER);
frame.add(microphonePanel, BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
}
public void speak(String output)
{
speakerField.setText(output);
}
public void run(Connection c)
{
connect = c;
}
private JTextArea speakerField;
private Connection connect;
}
And I get the fail in the as in the topic, I think I know what the problems is.
is it not that i need something like a main method to make it run:
public static void main(String[] args)
but where to put the method and what to write I'm not certain about, should I put the entire program in the main method ? or something else

New Topic/Question
Reply



MultiQuote






|