Hey guys! I am kind of new to Java and am having issues understanding why this code will not run. Any advise would be greatly appreciated! Thanks in advance!
// Phone.java
// Program creates a GUI that resembles a phone with functionality.
import java.awt.*;
import java.awt.GridLayout;
import java.awt.event.*;
import javax.swing.*;
public class Phone extends JFrame
{
private JButton keyJButton[];
private JPanel keyJPanel;
private JPanel lcdJPanel;
private JTextArea lcdJTextArea;
private String lcdOutput = "";
private int count;
// constructor sets up GUI
public Phone()
{
super( "Phone" );
lcdJTextArea = new JTextArea( 4, 15 );
lcdJTextArea.setEditable( false );
lcdJPanel.add( lcdJTextArea );
keyJButton = new JButton[ 15 ];
// initialize all digit key Buttons
for ( int i = 3; i <= 11; i++ )
keyJButton[ i ] = new JButton( String.valueOf( i - 2 ) );
// initialize all non-digit key Buttons
keyJButton[ 0 ] = new JButton( "Send" );
keyJButton[ 1 ] = new JButton( "clr" );
keyJButton[ 2 ] = new JButton( "End" );
keyJButton[ 12 ] = new JButton( "*" );
keyJButton[ 13 ] = new JButton( "0" );
keyJButton[ 14 ] = new JButton( "#" );
keyJButton[ 0 ].addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
lcdOutput = "Calling...\n\n" + lcdOutput;
lcdJTextArea.setText( lcdOutput );
} // end method actionPerformed
} // end new ActionListener
); // end addActionListener call
keyJButton[ 1 ].addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
if ( lcdOutput.length() == 0 ||
lcdOutput.substring( 0, 1 ).equals( "C" ) )
return;
else
{
lcdOutput = lcdOutput.substring( 0, ( lcdOutput.length() - 1 ) );
lcdJTextArea.setText( lcdOutput );
} // end else
} // end method actionPerformed
} // end object ActionLstener
); // end addActionListener call
keyJButton[ 2 ].addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
lcdJTextArea.setText( " " );
lcdOutput = "";
} // end method actionPerformed
} // end new ActionListener
); // end ActionListener call
for ( int i = 3; i <= 14; i++ )
{
keyJButton[ i ].addActionListener(
new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
lcdOutput += e.getActionCommand();
if ( lcdOutput.substring( 0, 1 ).equals( "C" ) )
return;
lcdJTextArea.append( e.getActionCommand() );
} // end method actionPerformed
} // end new ActionListener
); // end addActionListener call
} // end for loop
// set keyJPanel layout to grid layout
keyJPanel = new JPanel();
keyJPanel.setLayout( new GridLayout( 5, 3 ) );
// add buttons to keyJPanel
for ( int i = 0; i <= 14; i++ )
keyJPanel.add( keyJButton[ i ] );
// add components to container
add( lcdOutput, BorderLayout.NORTH );
} // end Phone constructor
private void add(String lcdOutput, String NORTH) {
throw new UnsupportedOperationException("Not yet implemented");
}
} // end class Phone
// PhoneTest.java
// Program creates a GUI that resembles a phone with functionality.
import javax.swing.JFrame;
public class PhoneTest
{
// execute application
public static void main( String args[] )
{
Phone application = new Phone();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
application.setSize( 200, 300 );
application.setVisible( true );
} // end main
} // end class PhoneTest
I get this compilation error when trying to complie.
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
at Phone.<init>(Phone.java:29) * actually line 27 in this post
at PhoneTest.main(PhoneTest.java:8) * actually line 9 in this post
I'm sure this is a newbie error. Thanks all!