当前位置: 首页 > 知识库问答 >
问题:

令牌上的Java语法错误,构造错误

杜凯
2023-03-14

我正在做一个java自动售货机操作系统,我刚刚将我的原始项目导入到eclipse中,并添加了一个guy页面,从那以后,无论我做什么,它到处都是错误,我能得到一些帮助吗?现在的主要错误是“令牌的语法错误,错误的构造”,如果代码是坏的或者是低效率的,我会提前道歉。

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个答案

家西岭
2023-03-14

你有

class OS {

而且还

public class OS extends Frame {

第一个应该去掉。

class OS {
slot.d(activate);
 类似资料:
  • 我写了一个java代码作为我大学作业的练习。在if-else语句中,我得到了一个错误:“syntax error on token”if“,delete this token”。我想我犯了一些小错误,比如;.但是我找不出那个错误 我注释了显示错误的区域。下面是我写的代码。

  • 所以我在第37行的else if中出现了错误,我不知道为什么会发生这种情况。IDE说:“令牌”else“语法错误,删除这个令牌”。多谢了。

  • 问题内容: 这是我的代码一直在给问题。 我不知道为什么要这么做。 编辑: 我已根据您的要求进行了编辑,以查看更多代码。 问题答案: 您要在课程外声明一个字段: 它必须放在一个类中:

  • 问题内容: 我在这里很陌生,但让我们直接解决这个问题:当我为一个类项目计算器编写以下代码时,遇到了“令牌错误”。这是完整的错误消息: 我写了这段代码: 这就是代码,我注释了令牌错误所在的区域。也许解决方案就对了。我希望我的代码成为一个计算器,以便你们可以修正我的代码,使其不与数学运算冲突。谢谢,感谢您的帮助。 问题答案: 问题是分号之后的分号。 语法为 条件 expression-or-block

  • 我正在尝试使用命令终端编译以下文件。 门票tatus.java: 运行此命令后: 我得到: 文件结构: 版本: Ubuntu:18.04 提前谢谢!。抱歉,我是java新手。

  • 我不知道该怎么做,是不是有一个错误,我遵循了所有的步骤,在教程中,我正在看。它只是说删除令牌