2013-05-25 2 views
1

메신저 자바 자동 판매기 OS를하고있는 중이며 방금 원래 프로젝트를 이클립스로 가져 와서 사람 페이지를 추가 한 후 오류가있는 곳은 어디에도 던지지 않았습니다. 내가 뭘 도와 드릴까요? 주요 오류는 '토큰에 대한 구문 오류, 잘못 배치 된 구문 (s)'입니다. 코드가 잘못되었거나 스크랩이 비효율적 인 경우 사전에 사과드립니다.자바 구문 오류가 토큰에 잘못 배치 된 구문

package JavaOS; 

class OS { 

import javax.swing.JButton; 
import javax.swing.JOptionPane; 
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import java.awt.Color; 
import java.awt.event.ActionListener; 
import java.awt.event.ActionEvent; 
import java.io.*; 
import java.util.*; 

public class OS extends Frame { 

    ImageIcon ironman3 = new ImageIcon ("H:\\School\\TECH\\Javaimages\\ironman3"); 
    ImageIcon dredd  = new ImageIcon ("H:\\School\\TECH\\Javaimages\\dredd"); 
    ImageIcon indiana = new ImageIcon ("H:\\School\\TECH\\Javaimages\\indiana"); 
    ImageIcon startrek = new ImageIcon ("H:\\School\\TECH\\Javaimages\\startrek"); 

    public static String newline = System.getProperty("line.separator"); 
    private static final long serialVersionUID = 1L; 

    private static Object activate; 

    String movie     = null; 
    static boolean rightCreditCard = false; 

    public static void main(String[] args) throws IOException { 



     slot.d(activate); 

     beginProgram(); 

     Welcome_GUI(); 

     System.out.println("Part A - Intalising JFrame Windows"); 

     checkCard(); 

     if (rightCreditCard == false) { 
      JFrame parent = new JFrame(); 
      JOptionPane.showMessageDialog(parent, "Your Credit Card is invalid!"); 
      checkCard(); 
     } else { 
      JFrame parent = new JFrame(); 
      JOptionPane.showMessageDialog(parent, "Your Credit Card is valid!"); 
     } 
    } 

     //Scanner scanner = new Scanner(System.in); 
     //System.out.println(scanner.nextLine()); 

     //PrintWriter out = new PrintWriter(new FileWriter("H:\\School\\TECH\\JavaFileOutputs\\outputfile.txt")); 
     //out.print("Hello "); 
     //out.println("world"); 
     //out.close(); 

     //BufferedReader in = new BufferedReader(new FileReader("H:\\School\\TECH\\JavaFileOutputs\\outputfile.txt")); 
     //String text = in.readLine(); 
     //in.close(); 

     //System.out.println(text); 

      public static void beginProgram() { 

       Object[] options = { "OK", "Cancel" }; 

       int JOP_Start = JOptionPane.showOptionDialog(null, 
        "Do you want to begin program?", 
        "Start?", 
        JOptionPane.YES_NO_OPTION, 
        JOptionPane.QUESTION_MESSAGE, 
        null, 
        options, 
        options[0]); 

       if (JOP_Start == JOptionPane.NO_OPTION) 
       { 
       System.out.println("Program Terminated"); 
       System.exit(0); 
       } 
      } 

      public static void checkCard() { 
      String number = JOptionPane.showInputDialog("Enter your creditcard");; 

      int sum1=0,sum2=0; 

      //find the first Sum 
      for(int i=number.length()-1;i>=0;i=i-2) 
       { 
        sum1 = sum1 + Character . getNumericValue(number . charAt(i)); 
       } 

      //find the second sum 
      for(int i=number.length()-2;i>=0;i=i-2) 
      { 
       int doublenumber = 2 * Character . getNumericValue(number.charAt(i)); 
       String doublestring = Integer.toString(doublenumber); 
       //System.out.println(doublenumber+ " "+doublestring); 
       for(int j=0;j<doublestring.length();j++) 
       { 
        //System.out.println(Character . getNumericValue(doublestring.charAt(j))); 
        sum2 = sum2 + Character . getNumericValue(doublestring.charAt(j)) ; 
       } 
      } 
      //System.out.println(sum1+" "+sum2); 

      //Check the result 
      if((sum1+sum2)%10 == 0) { 
       System.out.println("Valid Credit Card!"); 
       JFrame parent = new JFrame(); 
       JOptionPane.showMessageDialog(parent, "Your Credit Card is valid!"); 
       boolean rightCreditCard = true; 
      } 
      else 
      { 
       System.out.println("Invalid Credit Card!"); 
       boolean rightCreditCard = false; 

       //Suggesting right check digit 
       System.out.println(sum1+sum2); 
       int totalsum = sum1+sum2; 
       int lastdigitoftotalsum = totalsum%10; 
       int numbertoaddtocheckdigit = 10 - lastdigitoftotalsum; 
       int userenteredcheckdigit = Character . getNumericValue(number . charAt(number.length()-1)); 
       int progsuggestedcheckdigit = userenteredcheckdigit + numbertoaddtocheckdigit; 
       System.out.println(lastdigitoftotalsum + " " + numbertoaddtocheckdigit + " " + userenteredcheckdigit + " "+ progsuggestedcheckdigit); 
       System.out.println("The check digit should be " + progsuggestedcheckdigit); 



       //////////////////////////// 
       //CREDIT CARD CHECK /\ END// 
       ////////////////////////////  

      } 
    } 

      public static void rentMovie() { 

      Object[] options = { "OK", "Cancel" }; 

      int accept = JOptionPane.showOptionDialog(null, 
       "Are you shoure you wish to rent this movie?", 
       "???", 
       JOptionPane.YES_NO_OPTION, 
       JOptionPane.WARNING_MESSAGE, 
       null, 
       options, 
       options[0]); 

      if (accept == JOptionPane.NO_OPTION) 
      { 
       System.out.println("You have not rented moive"); 
      } 
      if (accept == JOptionPane.YES_OPTION) 
      { 
       System.out.println("You have rented moive"); 
       slot.d(activate); 
       System.out.println("Slot dispenser activated"); 
      } 
     } 

      public static void overDue() { 

     } 

      public static void delay(int i) { 
      try { //a wait or delay 
       Thread.sleep(i); 
      } catch(InterruptedException ex) { 
       Thread.currentThread().interrupt(); 
      } 
    } 

      public static void Welcome_GUI() { 
       JFrame frame = new JFrame ("MyPanel"); 
       frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); 
       frame.getContentPane().add (new JPanel()); 
       frame.pack(); 
       frame.setVisible (true); 

       class MyPanel extends JPanel { 
        private JLabel jcomp1; 
        private JLabel jcomp2; 
        private JButton jcomp3; 
        private JLabel jcomp4; 
        private JButton jcomp5; 
        private JButton jcomp6; 
        private JButton jcomp7; 
        private JLabel jcomp8; 
        private JLabel jcomp9; 
        private JLabel jcomp10; 
        private JLabel jcomp11; 
        private JLabel jcomp12; 
        private JLabel jcomp13; 
        private JLabel jcomp14; 
        private JLabel jcomp15; 
        private JLabel jcomp16; 

        public MyPanel() { 
         //construct components 
         jcomp1 = new JLabel (" Welcome To Video Pro 2000-XD"); 
         jcomp2 = new JLabel (" Iron Man 3"); 
         jcomp3 = new JButton ("Rent"); 
         jcomp4 = new JLabel ("Dredd 3D"); 
         jcomp5 = new JButton ("Rent"); 
         jcomp6 = new JButton ("Rent"); 
         jcomp7 = new JButton ("Rent"); 
         jcomp8 = new JLabel ("Indiana Jones"); 
         jcomp9 = new JLabel ("Star Trek"); 
         jcomp10 = new JLabel ("Into Darkness"); 
         jcomp11 = new JLabel ("Kindom Of the "); 
         jcomp12 = new JLabel ("Crystal Skull"); 
         jcomp13 = new JLabel ("PIC _STAR_TREK"); 
         jcomp14 = new JLabel ("PIC_INDINA_JONES"); 
         jcomp15 = new JLabel ("PIC_IRONMAN3"); 
         jcomp16 = new JLabel ("PIC_DREDD_3D"); 

         //adjust size and set layout 
         setPreferredSize (new Dimension (1241, 746)); 
         setLayout (null); 

         //add components 
         add (jcomp1); 
         add (jcomp2); 
         add (jcomp3); 
         add (jcomp4); 
         add (jcomp5); 
         add (jcomp6); 
         add (jcomp7); 
         add (jcomp8); 
         add (jcomp9); 
         add (jcomp10); 
         add (jcomp11); 
         add (jcomp12); 
         add (jcomp13); 
         add (jcomp14); 
         add (jcomp15); 
         add (jcomp16); 

         //set component bounds (only needed by Absolute Positioning) 
         jcomp1.setBounds (285, 35, 210, 35); 
         jcomp2.setBounds (280, 170, 80, 30); 
         jcomp3.setBounds (280, 205, 100, 25); 
         jcomp4.setBounds (400, 170, 70, 30); 
         jcomp5.setBounds (400, 205, 100, 25); 
         jcomp6.setBounds (280, 580, 100, 25); 
         jcomp7.setBounds (400, 565, 100, 25); 
         jcomp8.setBounds (280, 500, 100, 25); 
         jcomp9.setBounds (400, 510, 100, 25); 
         jcomp10.setBounds (400, 535, 100, 25); 
         jcomp11.setBounds (280, 525, 100, 25); 
         jcomp12.setBounds (280, 550, 100, 25); 
         jcomp13.setBounds (530, 400, 220, 326); 
         jcomp14.setBounds (40, 400, 220, 326); 
         jcomp15.setBounds (40, 40, 220, 326); 
         jcomp16.setBounds (530, 40, 220, 326); 
        } 

      } 
     } 
    } 

답변

1

당신은

class OS { 

과 첫 번째가 제거되어야한다 또한

public class OS extends Frame { 

있습니다.

이외의 개체 '슬롯'이 선언되고 초기화되지 않았습니다.

class OS { 

slot.d(activate); 

파일의 두 줄을 제거한 후 컴파일하고 실행해야합니다.

+0

스레드 "main"의 예외 java.lang.UnsupportedClassVersionError : JavaOS/OS : 지원되지 않는 major.minor 버전 51.0 및 MyPanel이 사용되지 않음 – Technosasquach

+0

참조 : http://stackoverflow.com/questions/11239086/java-lang-unsupportedclassversionerror-unsupported-major-minor-version-51-0 및이 답변은 http://stackoverflow.com/questions/15689980/simple-java-program-can-not-be- 실행/15690095 # 15690095 –

+0

놀라운 와우 감사합니다. – Technosasquach

관련 문제