私はJava自動販売機OSをやっていて、元のプロジェクトをEclipseにインポートしてガイページを追加したところですが、それ以来、何をしてもどこにでもエラーがスローされています。現在の主なエラーは「トークンの構文エラー、配置されていない構造」です。コードが悪いか、スクラップが散らばっていて非効率的である場合は、事前に謝罪します。
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);
}
}
}
}