Driv
March 26th, 2008, 09:00 PM
I programmed this short assignment in class today, but it has a very odd problem. The objective was to make a small program that a user could enter in the name of a shape, and it would draw the shape onto a window, and draw out the name of the shape.
It runs fine on the computer I programmed it on, and on my home computer I'm using now. However when it runs on anyone else's computer that I've tested (including the other computers in the lab running the same software/configuration). It will only print one or two shapes before not printing any more. It had my professor stumped, and I was hoping you guys would be able to shed some light on it.
I appreciate any response!
import java.awt. *;
import javax.swing. *;
//Font Setup
public class FontsAndShapes extends JFrame
{
public FontsAndShapes()
{
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE );
setSize(400,500);
setVisible(true);
}
public void paint (Graphics g)
{
String enterGuess = "Woot";
enterGuess = JOptionPane.showInputDialog("Enter a shape");
while (true)
{
if (enterGuess.equalsIgnoreCase("Square"))
{
//Draw and Write Sq
g.setColor (new Color (255, 0, 0));
g.setFont (new Font ( "Monospaced", Font.BOLD, 12) );
g.drawString ( "Square!" , 100, 100);
g.fillRect (30, 50, 25,25);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else if(enterGuess.equalsIgnoreCase("Rectangle"))
{
//Draw and Write Rec
g.setColor (new Color (238, 238, 0));
g.setFont (new Font ( "SansSerif", Font.BOLD, 12) );
g.fillRect (30, 100, 25, 50);
g.drawString ( "Rectangle!" , 100, 150);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else if(enterGuess.equalsIgnoreCase("Circle"))
{
//Draw and Write Circle
g.setColor (new Color (153, 238, 0));
g.fillOval (30, 150, 25, 25);
g.setFont (new Font ( "Serif", Font.BOLD, 12) );
g.drawString ( "Circle!" , 100, 200);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else if(enterGuess.equalsIgnoreCase("Oval"))
{
//Draw and Write Oval
g.setColor (new Color (85, 222, 117));
g.fillOval (30, 200, 25, 50);
g.setFont (new Font ( "Gigi", Font.BOLD, 12) );
g.drawString ( "Oval!" , 100, 250);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else
{
g.setFont (new Font ( "Times New Roman", Font.BOLD, 12) );
g.drawString ( "You entered an invalid shape!" , 25, 300);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
}
}
public static void main (String [] arg)
{
FontsAndShapes Demo = new FontsAndShapes ();
}
}
It runs fine on the computer I programmed it on, and on my home computer I'm using now. However when it runs on anyone else's computer that I've tested (including the other computers in the lab running the same software/configuration). It will only print one or two shapes before not printing any more. It had my professor stumped, and I was hoping you guys would be able to shed some light on it.
I appreciate any response!
import java.awt. *;
import javax.swing. *;
//Font Setup
public class FontsAndShapes extends JFrame
{
public FontsAndShapes()
{
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE );
setSize(400,500);
setVisible(true);
}
public void paint (Graphics g)
{
String enterGuess = "Woot";
enterGuess = JOptionPane.showInputDialog("Enter a shape");
while (true)
{
if (enterGuess.equalsIgnoreCase("Square"))
{
//Draw and Write Sq
g.setColor (new Color (255, 0, 0));
g.setFont (new Font ( "Monospaced", Font.BOLD, 12) );
g.drawString ( "Square!" , 100, 100);
g.fillRect (30, 50, 25,25);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else if(enterGuess.equalsIgnoreCase("Rectangle"))
{
//Draw and Write Rec
g.setColor (new Color (238, 238, 0));
g.setFont (new Font ( "SansSerif", Font.BOLD, 12) );
g.fillRect (30, 100, 25, 50);
g.drawString ( "Rectangle!" , 100, 150);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else if(enterGuess.equalsIgnoreCase("Circle"))
{
//Draw and Write Circle
g.setColor (new Color (153, 238, 0));
g.fillOval (30, 150, 25, 25);
g.setFont (new Font ( "Serif", Font.BOLD, 12) );
g.drawString ( "Circle!" , 100, 200);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else if(enterGuess.equalsIgnoreCase("Oval"))
{
//Draw and Write Oval
g.setColor (new Color (85, 222, 117));
g.fillOval (30, 200, 25, 50);
g.setFont (new Font ( "Gigi", Font.BOLD, 12) );
g.drawString ( "Oval!" , 100, 250);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
else
{
g.setFont (new Font ( "Times New Roman", Font.BOLD, 12) );
g.drawString ( "You entered an invalid shape!" , 25, 300);
enterGuess = JOptionPane.showInputDialog("Enter a shape");
}
}
}
public static void main (String [] arg)
{
FontsAndShapes Demo = new FontsAndShapes ();
}
}