Nicole Smith

Greenhorn
+ Follow
since Jun 20, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nicole Smith

I'm almost done taking my first java class and would like to buy a book about learning java that is straightforward and easy to understand, hopefully w/alot of code examples. Does anyone know a good one? Also, how about more of a reference book for java?
Thanks alot!
22 years ago
how do I clear an applet window when I'm doing continual input? It just keeps writing over itself.
import javax.swing.*; //import javax.swing package
import java.text.DecimalFormat; //import DecimalFormat for spaces after decimal
import java.awt.Graphics; //import class Graphics
i
public class assign4test extends JApplet
{
public void paint(Graphics g)
{

String empName, rate, hours;
int loopControl;
double hrRate, totalPay, hrs;
DecimalFormat twoDigits = new DecimalFormat("0.00");
loopControl = 0;
while(loopControl != 1)
{
empName = JOptionPane.showInputDialog("Enter employee name: ");
hours = JOptionPane.showInputDialog("Enter number of hours worked: ");
rate = JOptionPane.showInputDialog("Enter hourly rate: ");
hrs = Double.parseDouble(hours);
hrRate = Double.parseDouble(rate);
if (hrs <= 40)
{
totalPay = hrs * hrRate;
}
else
{
totalPay = (40 * hrRate) + ((hrs - 40) * (hrRate * 1.5));
}
g.drawString("Employee name - " + empName, 25, 25);
g.drawString("Gross pay - $" + twoDigits.format(totalPay), 25, 45);

loopControl = JOptionPane.showConfirmDialog(null, "Input another employee?", "Get user response", JOptionPane.YES_NO_OPTION);
When I click on Yes for input another employee, the first info is staying on the applet and the next info is just written over it. How do I clear it between each set of inputted info?
22 years ago
I figured out something- I had put:
DecimalFormat twoDigits = new DecimalFormat("0.00");
in a while loop, so I moved it to outside the while loop but still in the paint method and now it works, go figure.
22 years ago
After inputting a string number with:
hours = JOptionPane.showInputDialog("Enter hours worked: ");
and changing to a double:
hrs = Double.parseDouble(hours);
how can I display the number with two numbers to the right of the decimal point (i.e. 48.75)? I was using DecimalFormat:
JOptionPane.showMessageDialog(null, "Number of hours is :" + twoDigits.format(hrs), JOptionPane.INFORMATION_MESSAGE);
when it was an application, but am having trouble when doing it as an applet with g.drawString .
22 years ago