|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Homework - Please could i have some assistance
Hi all, i am new here..i am actually here for one reason so far, but the site looks awesome, so i will be around.
i was wondering if any of you would mind helping me script a few commands. i can create the gui and everything..i just need the commands to be put in, now im not very good at that. if you can help, plz reply and i will gladly upload the .java files. thnx to all ![]() |
|
#2
|
||||
|
||||
|
This is a help section. Not a do-it-for-you-so-that-you-don't-have-to-and-will-never-learn-that-way section. Adding listeners is quite easy =)
__________________
"Java makes impossible things possible, but makes easy things difficult." - Somebody
|
|
#3
|
|||
|
|||
|
ok fair enough, could you help me out with a few links or examples to using the math.random function. i am using netbeans. my instructor said i must use textpad...but he still lives in the prehistoric age.
i basically need to implement, math.random then generate random numbers in individual text fields, the user with the highest value wins. im a technician/network engineer..not a coder. |
|
#4
|
||||
|
||||
|
You change a text fields value using the .setText(<string>) method. As for a random, do you want it to be in a range, or just some number?
|
|
#5
|
|||
|
|||
|
thnx for the help :-)
i want it to do a math.random of values between 0(or)1 and 50 (so in essence a range of int's) then print them to indivdual boxes...is there a way i can link multiple objects to work on one array, so i can tell it math.random (init function of random numbers) while (print text to (textboxset1.setText(math.random output)); cuz it will be a b**ch if i have to code for each individual box. i am using net beans as my builder...then copy paste to textpad to see if it will run. ok here is screen shot of my app (for some reason it wont display the pic..here is direct code to pic) Code:
http://i272.photobucket.com/albums/jj191/EldHawke/applet.jpg and here is my code Code:
public class applet extends java.applet.Applet {
/** Initializes the applet appplet */
@Override
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
resize (322,136);
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void initComponents() {
p1lbl = new javax.swing.JLabel();
p2lbl = new javax.swing.JLabel();
p1t1 = new javax.swing.JTextField();
p2t1 = new javax.swing.JTextField();
p2t2 = new javax.swing.JTextField();
p1t2 = new javax.swing.JTextField();
p2t3 = new javax.swing.JTextField();
p1t3 = new javax.swing.JTextField();
p2t14 = new javax.swing.JTextField();
p1t4 = new javax.swing.JTextField();
stbt = new javax.swing.JButton();
p1lblt = new javax.swing.JLabel();
p2lblt = new javax.swing.JLabel();
p1t = new javax.swing.JTextField();
p2t = new javax.swing.JTextField();
p1lbl.setText("Player 1 :");
p2lbl.setText("Player 2 :");
p1t1.setEditable(false);
p2t1.setEditable(false);
p2t2.setEditable(false);
p1t2.setEditable(false);
p2t3.setEditable(false);
p1t3.setEditable(false);
p2t14.setEditable(false);
p1t4.setEditable(false);
stbt.setText("Start!");
stbt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stbtActionPerformed(evt);
}
});
p1lblt.setText("Player 1 Total :");
p2lblt.setText("Player 2 Total :");
p1t.setEditable(false);
p2t.setEditable(false);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(p1lbl)
.addComponent(p2lbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(p2t1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p1t1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(p2t2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p1t2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(stbt)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(p2t3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p1t3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(p1t4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(p1lblt))
.addGroup(layout.createSequentialGroup()
.addComponent(p2t14, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(p2lblt)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(p2t, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p1t, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(p1t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p1lbl))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(p2t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p2lbl)))
.addGroup(layout.createSequentialGroup()
.addComponent(p1t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(p2t2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(p1t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(p2t3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(p1t4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(p1lblt)
.addComponent(p1t, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(p2lblt)
.addComponent(p2t, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(p2t14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addComponent(stbt)
.addContainerGap(25, Short.MAX_VALUE))
);
}
private void stbtActionPerformed(java.awt.event.ActionEvent evt) {
}
private javax.swing.JLabel p1lbl;
private javax.swing.JLabel p1lblt;
private javax.swing.JTextField p1t;
private javax.swing.JTextField p1t1;
private javax.swing.JTextField p1t2;
private javax.swing.JTextField p1t3;
private javax.swing.JTextField p1t4;
private javax.swing.JLabel p2lbl;
private javax.swing.JLabel p2lblt;
private javax.swing.JTextField p2t;
private javax.swing.JTextField p2t1;
private javax.swing.JTextField p2t14;
private javax.swing.JTextField p2t2;
private javax.swing.JTextField p2t3;
private javax.swing.JButton stbt;
}
|
|
#6
|
||||
|
||||
|
Use an ArrayList
You can add all the text boxes into an ArrayList and then use a loop to accomplish your task.
__________________
When the programming world turns decent, the real world will turn upside down.
|
|
#7
|
|||
|
|||
|
thnx for the help you guys, i managed to do it :-)
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Homework - Please could i have some assistance |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|