freelanceprogrammers.org Forum Index » Java

second request??


View user's profile Post To page top
caldrq Posted: Fri Apr 16, 2004 8:32 am


Joined: 16 Apr 2004

Posts: 9
second request??
Hey folks, this is an easy one. I am very new to Java so PLEASE..............
Any help you can provide would be greatly appriciated. This is my first array
applet. It is supposed to input 5 numbers between 10 and 100. As each number is
read, display only if it is not a duplicate. Can you please tell me how to use
method setText to update results after each value is input? My html file is
attached here. My applet runs without errors but the display is incomplete. Here
is what I have so far:

// Applet that inputs 5 numbers between 10 and 100 using a one deminsional
array.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Container;

public class A7_13 extends JApplet implements ActionListener
{

JLabel enterLabel;
JTextField enterField;
JTextArea textArea;
int array []; // create array
int size = 0, skey, intkey;

// set up applet`s GUI
public void init()
{
// get content pane
Container container = getContentPane();
container.setLayout( new FlowLayout() );

// set up JLabel and JTextField for user input
enterLabel = new JLabel( "Enter Number: " );
container.add( enterLabel );

enterField = new JTextField( 7 );
container.add( enterField );

// register this applet as enterField`s action listener
enterField.addActionListener( this );

// set up display area
JTextArea textArea = new JTextArea( 1, 15 );
container.add( textArea );

} // end method init


// obtain user input
public void actionPerformed( ActionEvent actionEvent )
{
String skey = actionEvent.getActionCommand();
intkey = Integer.parseInt( skey );
if (intkey < 10 ||intkey > 100)
showStatus( "invaild entry" );
else
if ( size == 0 )
showStatus( "Number entered: " + intkey );
textArea.append( intkey + "" );
//
array[0] = intkey;
size ++;

if (size > 0 && size <= 5)

for (int i = 0; i < size; i++ )
if ( array[i] == intkey )
array[size] = intkey;

else

System.exit( 0 ); // terminate applet



[Non-text portions of this message have been removed]



------------------------------------------------------------------------------
Yahoo! Groups Links

a.. To visit your group on the web, go to:
http://groups.yahoo.com/group/beginnersclub/

b.. To unsubscribe from this group, send an email to:
beginnersclub-unsubscribe@yahoogroups.com

c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



[Non-text portions of this message have been removed]
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help