Results 1 to 15 of 15
- 06-03-2010, 04:12 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 42
- Rep Power
- 0
- 06-03-2010, 04:45 PM #2
this sounds like a JTable
- 06-03-2010, 05:54 PM #3
Use a text field to get data from a user.
- 06-03-2010, 06:44 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 42
- Rep Power
- 0
thanks for your replies
the number of students will be given by the user
i now know how can i add textfields as the number entered by the user, but the question is, how can i store the entered names (by user) in an array??
- 06-03-2010, 06:48 PM #5
1) get the data out of the text field into a String. Read the API doc for the text field class for which method to use
2) put a reference in the array to that String: array[ix] = string;
- 06-03-2010, 07:15 PM #6
Member
- Join Date
- Jun 2010
- Posts
- 42
- Rep Power
- 0
i am sorry, i am a beginner in Java, and i did not really understand all what you posted
let me give an idea of what i am doing in my program, the program is to ask the user he enter a number of students. then the same number of textfields must be displayed. the user has to enter students names, and grades for 6 subjects.
my question is if i want to display all students names and grades in a table, find the averages of each student and each subject? how can i store the entered grade of student name in the array. should i use only one textfield for students names and one for grades? if yes, how can get the data from the textfield and store it in the array
- 06-03-2010, 08:16 PM #7
JTable would give a nicer but I'm not sure if a beginner would be up to it.
Otherwise use a layout manager like GridLayout to build simple table of text fields.
Are you going to get the names and grades one at a time from the user and then display them all after they have been processed? Does each student have grades for 6 courses?
Then the table would have 7 columns, one for name and 6 for grades. Plus maybe another column for the averages.
1) where do you get the grade? Input to a text field by user?how can i store the entered grade of student name in the array.
Read text field API doc for methods to get data from text field.
Once grade is in a String, convert it to number by method of Integer or Double class.
2) Store grade in an array?
Make an array of proper type: int or float. Decide which element to put the grade in and assign that element the grade: array[ix] = grade;
- 06-04-2010, 12:29 PM #8
Member
- Join Date
- Jun 2010
- Posts
- 42
- Rep Power
- 0
Many thanks for your help
but How many text fields i have to define?
- 06-04-2010, 02:01 PM #9
If there are 6 text flelds on a row and there are 6 rows, that would require 36.
- 06-04-2010, 03:58 PM #10
hope the following code give you some ideas how to implement your requirements
Java Code:import java.applet.Applet; import java.awt.BorderLayout; import javax.swing.JPanel; import javax.swing.JTextArea; public class Test extends Applet { private static final long serialVersionUID = 1L; public void init() { JTextArea area = new JTextArea(); area.setEditable(false); int[][] arr = { { 0, 1 }, { 1, 1 }, { 2, 1 } }; String str = ""; for (int r = 0; r < arr.length; r++) { str += "Array[" + r + "][1] = "; for (int c = 0; c < arr[r].length; c++) { str += arr[r][c] + " "; } str += "\n"; area.append(str); str = ""; } add(area, BorderLayout.CENTER); } }
modify the code according to your requirements.Last edited by j2me64; 06-04-2010 at 04:06 PM.
- 06-05-2010, 09:36 AM #11
Member
- Join Date
- Jun 2010
- Posts
- 42
- Rep Power
- 0
many thanks to all of you for your help
i just knew that textfields can be declared in an array :)
but there is one problem i do not know what how to solve it, which is where should i write the loops, should i create another public void main () and write it there?
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class students_grades extends Applet implements ActionListener {
Label title = new Label("<{This program calculate students grades in 6 subjects}>");
Label number_of_students = new Label("<{Inter the number of the students}>");
TextField number_of_students_ = new TextField(5);
Button View_Table = new Button ("View Table");
public void init( ) {
//setLayout();
add (title);
add (number_of_students);
add (number_of_students_);
add (View_Table);
number_of_students_.addActionListener(this);
View_Table.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
// to get the number of students entered by user
// String titles [8] = [No. , Student Name, Math, Comp, Salam, Arab, MGT, ORG];
String number_of_students_text = number_of_students_.getText();
int number_of_students_int = Integer.parseInt(number_of_students_text);
// define two arrays of textfield
TextField txtname []= new TextField [number_of_students_int];
TextField txtgrade [][] = new TextField [number_of_students_int][6];
// define two arrays ===> one for student names, and the other one for students grade
String students_names [] = new String [number_of_students_int];
float students_grades [][] = new float [number_of_students_int][6];
// add name text fields
for (int i=0; i<number_of_students_int; i++)
{
add (txtname[i]);
}
// add grade text fields in 2D array
for (int i=0; i<number_of_students_int ;i++)
{
for (int j=0; j<6 ; j++)
{
add (txtgrade[i][j]);
}
}
// get text from text fields and save it in the array
for (int i=0; i<number_of_students_int; i++)
{
students_names [i] = txtname[i].getText();
}
for (int i=0; i<number_of_students_int ;i++)
{
for (int j=0; j<6 ; j++)
{
String Container = txtgrade[i][j].getText();
int intContainer = Integer.parseInt(Container);
students_grades[i][j] = intContainer;
}
}
} // action performed
} // class
- 06-05-2010, 10:15 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 06-05-2010, 04:08 PM #13
Member
- Join Date
- Jun 2010
- Posts
- 42
- Rep Power
- 0
thanks Jos
I've heard this before but i don't know what it's really mean, cause I'm just a beginner
so, what exactly should i add? or change?
- 06-05-2010, 04:18 PM #14
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
My interpretation of what Jos is mainly saying is that you should RTFM. The information on JApplets can be obtained here.
Getting Started With Applets (The Java™ Tutorials > Deployment > Applets)
Have fun.
- 06-05-2010, 05:29 PM #15
Similar Threads
-
display bar graph with the help of java applet
By ras_pari in forum Java AppletsReplies: 1Last Post: 12-15-2009, 01:18 PM -
display a new jpanel in an applet
By toymachiner62 in forum Java AppletsReplies: 6Last Post: 10-18-2009, 11:10 PM -
How to display a java application using applet and XMl as backend in web page
By simple11 in forum Java AppletsReplies: 2Last Post: 04-26-2009, 06:36 AM -
How to display image from byte array in JPANEL
By waqasdaar in forum AWT / SwingReplies: 0Last Post: 03-22-2009, 12:11 AM -
Using reflection to create, fill, and display an array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks