|
-
re: beginner java need help
I am a beginner with Java & yes this is for a class. My group has spent 2
weeks trying to get this to work. We have to create a base converter with
a GUI interface. We have tried lots of things & nothing works. Now we are
getting this error "the action performed is not defined". Any suggestions
or tips would be greatly appreciated.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
import java.lang.String.*;
class Counter extends JPanel implements ActionListener
{
int base,value;
int currentnum=0;
char counting [] = { '0','1','2','3','4','5','6','7','8','9','A','B','C',
'D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z'};
protected JTextField baseField;
protected JTextField intrValField;
protected JTextField numDisplay;
protected JButton decButton= new JButton( "Decrement" );
protected JButton incButton= new JButton( "Increment" );
protected JButton resetButton= new JButton( "Reset" );
public Counter()
{
init();
doTheLayout( );
}
public void init()
{
decButton.addActionListener (this);
decButton.setActionCommand("dec");
incButton.addActionListener (this);
incButton.setActionCommand("inc");
resetButton.addActionListener (this);
resetButton.setActionCommand("re");
}
public void actionPerfomed(ActionEvent evt)
{
if ("dec".equals(evt.getActionCommand()))
{
initializeData();
DecInterval();
}
else if ("inc".equals(evt.getActionCommand()))
{
initializeData();
IncInterval();
}
else
{
numDisplay.setText("0");
intrValField.setText("0");
baseField.setText("0");
currentnum=0;
}
}
// Make all the objects
public void initializeData()
{
base= Integer.parseInt(baseField.getText());
value=Integer.parseInt(intrValField.getText());
}
// Layout all the objects
public void doTheLayout( )
{
JTextField baseField = new JTextField( 10 );
JTextField intrValField = new JTextField( 10 );
JTextField numDisplay= new JTextField(20);
numDisplay.setEditable(false);
JPanel bottomHalf = new JPanel( );
JPanel topHalf= new JPanel( );
// Layout the top half
topHalf.setLayout( new FlowLayout( ) );
topHalf.add( new JLabel( "Base" ) );
topHalf.add( baseField );
topHalf.add( new JLabel( "Interval" ) );
intrValField=new JTextField(10);
topHalf.add( intrValField );
intrValField.addActionListener(this);
topHalf.add( new JLabel( "Current Count" ) );
numDisplay=new JTextField(20);
topHalf.add( numDisplay );
// Layout the bottom half
bottomHalf.setLayout( new FlowLayout( ) );
bottomHalf.add( decButton );
bottomHalf.add( incButton );
bottomHalf.add( resetButton );
// Now layout GUI
setLayout( new BorderLayout( ) );
add( topHalf, "North" );
add( bottomHalf, "South" );
}
public void IncInterval()
{
int tempb=base;
currentnum=currentnum+value;
int tempnum=currentnum;
String output= " ";
int remainder, beginning;
while (tempnum > tempb)
{
remainder= tempnum % tempb;
output= counting[remainder] + output;
beginning= tempnum/tempb;
tempnum= beginning;
}
output= counting[remainder] + output;
numDisplay.setText(output);
}
public void DecInterval()
{
int tempb=base;
currentnum=currentnum-value;
int tempnum=currentnum;
String output= " ";
int remainder, beginning;
while (tempnum > tempb)
{
remainder= tempnum % tempb;
output= counting[remainder] + output;
beginning= tempnum/tempb;
tempnum= beginning;
}
output= counting[remainder] + output;
numDisplay.setText(output);
}
}
class CloseableFrame extends JFrame
{
public CloseableFrame( )
{
addWindowListener( new WindowAdapter( )
{
public void windowClosing( WindowEvent event )
{ System.exit( 0 ); }
}
);
}
}
class CounterGUI extends CloseableFrame
{
public static void main( String [] args )
{
JFrame f = new CounterGUI( );
f.setTitle( "The Counter" );
Container contentPane = f.getContentPane( );
contentPane.add( new Counter() );
f.pack( );
f.show( );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks