Erros = Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.next(Scanner.java:1463)
at drawingshapes.DrawingShapes.main(DrawingShapes.java:52)
I am new to java and i think my reach extends my grasp on this. I have searched for example codes via google and honestly i dont understand what im looking for.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package drawingshapes;
import java.awt.*;
import java.applet.*;
import java.util.Scanner;
import javax.swing.*;
/**
*
* @author AlaGondA
*/
public class DrawingShapes extends JApplet{
public static void drawRect1(Graphics gr){
drawRect(40, 40, 120, 120);
}
private static void drawOval(int i, int i0, int i1, int i2) {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void drawRect(int i, int i0, int i1, int i2) {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void drawLine(int i, int i0, int i1, int i2) {
throw new UnsupportedOperationException("Not yet implemented");
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
DrawingShapes canvas = new DrawingShapes(); //Define the Frame
JFrame frame = new JFrame();
frame.setSize(400, 400);
frame.getContentPane().add(canvas);
frame.setVisible(true);
Scanner input = new Scanner(System.in);
String choiceContinue = "y";
while (choiceContinue.equalsIgnoreCase("y")){ //create loop
{
System.out.print("Enter c, s, or t\r(C)ircle\r(S)quare\r(T)riangle\r\rEnter: ");
String drawType = input.next("");
if (drawType.equals("c")) {
frame.setSize(400, 400);
frame.getContentPane().add(canvas);
frame.setVisible(true);
drawOval(100, 100, 60, 60);
}
else if (drawType.equals("s")){
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(canvas);
frame.setVisible(true);
drawRect(40, 40, 120, 120);
}
else if(drawType.equals("t")){
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(canvas);
frame.setVisible(true);
drawLine(40, 40, 5, 75);
drawLine(5, 75, 75, 75);
drawLine(40,40, 75, 75);
}
else{
System.out.print("No Megusta");
}
}
System.out.println(); // end loop
System.out.println("Continue? (y/n) ");
choiceContinue = input.next();
System.out.println();
}
}
}
}

New Topic/Question
Reply



MultiQuote



|