Hi:
I'm writing my own programming language and I wanted to be able to save the code. When I compile i get this error message:
"cml.java": cannot resolve symbol: constructor cml (int[],int[],java.lang.String)in class cml at line 439, column 13
Here's the code:
//Cinnamon Machine Language Compiler
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class cml extends JFrame {
public String resultS = "*** Welcome to the C.M.L. Compiler. ***\n\n*** Please code a program and compile. ***";
JTextArea result = new JTextArea(resultS,20,10);
JTextField inputCode = new JTextField("CODE");
public Icon icn = new ImageIcon("icn.gif");
public Icon icn2 = new ImageIcon("icn2.gif");
public JPopupMenu popupMenu;
private ObjectOutputStream output;
private ObjectInputStream input;
JButton done = new JButton("Done with this C.M.L. line.",icn2);
JButton next = new JButton("Compile.", icn);
JButton reset = new JButton("Reset the compiler.");
JButton help = new JButton("Help me.");
JButton colors = new JButton("Color Scheme.");
JButton save = new JButton("Save...");
JButton open = new JButton("Open...");
Color coloring = Color.GREEN;
public int [] coder = new int[99];
public int [] coder2 = new int[99];
public int i = -1;
public int accum = 0;
public int operand = 0;
public int opCode = 0;
public int x = 0;
public int lines = 0;
public int code;
public int in;
public final String codes = result.getText();
public final int[] Scoder = coder;
public final int[] Scoder2 = coder2;
public UIManager.LookAndFeelInfo looks[];
public cml(){
//create frame
super("Cinnamon Machine Language (C.M.L.) Compiler");
setSize(750,450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
//done creating frame
Container content = getContentPane();
content.setBackground(Color.GRAY);
FlowLayout flowManager = new FlowLayout();
content.setLayout(flowManager);
reset();
popupMenu = new JPopupMenu();
popupMenu.add(save);
popupMenu.add(open);
addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent event){
checkForTriggerEvent(event);
}
public void mouseReleased(MouseEvent event){
checkForTriggerEvent(event);
}
private void checkForTriggerEvent(MouseEvent event){
if(event.isPopupTrigger()){
popupMenu.show(
event.getComponent(), event.getX(), event.getY() );
}
}
}
);
save.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
if(output != null) addRecord();
openFile();
}
}
);
open.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
openTheFile();
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
closeFile();
}
}
);
content.add(result);
result.setEditable(false);
result.setBackground(coloring);
content.add(next);
next.setForeground(Color.RED);
next.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
resultS+="\n\n*** Program loading completed ***\n"+
"*** Program execution begins ***";
result.setText(resultS);
compile();
}
}
);
content.add(inputCode);
inputCode.setForeground(Color.BLACK);
inputCode.addKeyListener(
new KeyListener(){
public void keyTyped(KeyEvent event){}
public void keyReleased(KeyEvent event){}
public void keyPressed(KeyEvent event) {
char key = event.getKeyChar();
if(key=='|'){
JOptionPane.showMessageDialog(null,"In the event that a suspect violates\n"+
"his/her shareware rights and this code is\n"+
"stolen, this section of code can be used in\n"+
"court to prove that the suspect is indeed\n"+
"guilty. Please do not plagarise.\n\n\n"+
"Oh yes, if you're smart enough to take\n"+
"this section of code out, don't think\n"+
"you've escaped because more of these are\n"+
"planted on CML.java.",
"Shareware Rights Violation = Imprisonment",
JOptionPane.ERROR_MESSAGE);
}
}
}
);
content.add(done);
done.setForeground(Color.BLUE);
done.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event){
try{
code = Integer.parseInt(inputCode.getText());
resultS += "\n" + lines + " = " + code;
result.setText(resultS);
lines++;
wtd();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Please enter a correct machine\n"+
"language statement.\n\n"+
"Exception: \n"+e, "ERROR",
JOptionPane.ERROR_MESSAGE);
reset();
}
}
}
);
content.add(reset);
reset.setBackground(Color.GRAY);
reset.setForeground(Color.WHITE);
reset.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event){
reset();
resultS = "*** Welcome to the C.M.L. Compiler. ***\n\n*** Please code a program and compile. ***";
result.setText(resultS);
inputCode.setText("CODE");
}
}
);
content.add(help);
help.setBackground(Color.GRAY);
help.setForeground(Color.WHITE);
help.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null,
"To learn CML got to: http://www.freewebs.com/pcssuck/index2.htm\n"+
"If you're having trouble with the actual compiler and not the\n"+
"language, email our team at code.rocket@gmail.com.\n\n\n"+
"This language was created by a 7th grader named Ian\n"+
"Cinnamon who followed MIT/UCLA's programming language \ndevelopment"+
" course.\n\n\nC.M.L. (Cinnamon Machine Language) copyright 2004.\n"+
"This compiler is shareware - please do not violate your rights.",
"Help Me!",JOptionPane.ERROR_MESSAGE);
}
}
);
content.add(colors);
colors.setBackground(Color.GRAY);
colors.setForeground(Color.WHITE);
colors.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event){
coloring = JColorChooser.showDialog(cml.this, "Choose a Color.", coloring);
if(coloring==null) coloring = Color.GREEN;
result.setBackground(coloring);
}
}
);
looks = UIManager.getInstalledLookAndFeels();
try{
UIManager.setLookAndFeel( looks[2].getClassName() );
SwingUtilities.updateComponentTreeUI( this );
}
catch(Exception e){
e.printStackTrace();
}
setContentPane(content);
}
private void openTheFile(){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(this);
if(result==JFileChooser.CANCEL_OPTION) return;
File fileName = fileChooser.getSelectedFile();
if(fileName==null || fileName.getName().equals(""))
JOptionPane.showMessageDialog(this, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
else{
try{
input=new ObjectInputStream(
new FileInputStream(fileName));
}
catch(IOException ion){
JOptionPane.showMessageDialog(this, "Error Opening File",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
private void openFile(){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode( JFileChooser.FILES_ONLY );
int result = fileChooser.showSaveDialog(this);
if(result == JFileChooser.CANCEL_OPTION)
return;
File fileName = fileChooser.getSelectedFile();
if( fileName==null || fileName.getName().equals( "" ) )
JOptionPane.showMessageDialog(this, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
else{
try{
output = new ObjectOutputStream(
new FileOutputStream( fileName ) );
readRecord();
}
catch(IOException e){
JOptionPane.showMessageDialog(this, "Error Opening File",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
public String getResult(){
return result.getText();
}
public int[] getCoder(){
return coder;
}
public int[] getCoder2(){
return coder2;
}
public void readRecord(){
cml record;
try{
record = (cml) input.readObject();
coder = getCoder();
coder2 = getCoder2();
result.setText( getResult() );
}
catch(EOFException end){
JOptionPane.showMessageDialog(this, "Error:\n"+end,
"Error", JOptionPane.ERROR_MESSAGE);
}
catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(this, "Unable to create object.",
"Class Not Found", JOptionPane.ERROR_MESSAGE);
}
catch(IOException ioException){
JOptionPane.showMessageDialog(this, "Error during read from file.",
"Read Error", JOptionPane.ERROR_MESSAGE);
}
}
private void closeFile(){
try{
input.close();
output.close();
System.exit( 0 );
}
catch(IOException io){
JOptionPane.showMessageDialog(this, "Error closing file",
"Error", JOptionPane.ERROR_MESSAGE);
System.exit( 1 );
}
}
public void addRecord(){
cml cql;
for(int s = 0; s < 99; s++) {
Scoder[s] = coder[s];
}
for(int a = 0; a < 99; a++) {
Scoder2[a] = coder2[a];
}
try{
cql = new cml(getCoder(), getCoder2(), getResult());
output.writeObject(cql);
output.flush();
reset();
}
catch(NumberFormatException fe){
JOptionPane.showMessageDialog(this, "Error: \n"+fe,
"NumberFormatException",
JOptionPane.ERROR_MESSAGE);
}
catch(IOException ioe){
JOptionPane.showMessageDialog(this, "Error: \n"+ioe+"\n\n"+
"Error writing to file",
"IOException", JOptionPane.ERROR_MESSAGE);
}
closeFile();
}
void reset(){
i = -1;
accum = 0;
operand = 0;
opCode = 0;
x = 0;
lines = 0;
code = 0;
in = 0;
for(int g = 0; g < 99; g++){
coder[g] = 0;
coder2[g] = 0;
}
}
void wtd(){
try{
opCode = code / 100;
operand = code % 100;
coder[lines] = code;
x++;
inputCode.setText("CODE");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Please enter a correct machine\n"+
"language statement.\n\n"+
"Exception: \n"+e, "ERROR",
JOptionPane.ERROR_MESSAGE);
reset();
}
}
void compile(){
for(in = 0; in<lines; in++){
int pcode = coder[in];
if (pcode/100 == 10) {
read();
}
else if (pcode/100 == 11) {
write();
}
else if (pcode/100 == 20) {
load();
}
else if (pcode/100 == 21) {
store();
}
else if (pcode/100 == 30) {
add();
}
else if (pcode/100 == 31) {
sub();
}
else if (pcode/100 == 32) {
div();
}
else if (pcode/100 == 33) {
mul();
}
}
}
void mul(){
accum*=coder2[coder[in]%100];
if(coder[in]/100==11){
write();
}
if(coder[in]/100==10){
read();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==32){
div();
}
}
void div(){
accum/=coder2[coder[in]%100];
if(coder[in]/100==11){
write();
}
if(coder[in]/100==10){
read();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==33){
mul();
}
}
void sub(){
accum-=coder2[coder[in]%100];
if(coder[in]/100==11){
write();
}
if(coder[in]/100==10){
read();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==32){
div();
}
if(coder[in]/100==33){
mul();
}
}
void add(){
accum+=coder2[coder[in]%100];
if(coder[in]/100==11){
write();
}
if(coder[in]/100==10){
read();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==32){
div();
}
if(coder[in]/100==33){
mul();
}
}
void store(){
coder2[coder[in]%100] = accum;
if(coder[in]/100==11){
write();
}
if(coder[in]/100==10){
read();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==32){
div();
}
if(coder[in]/100==33){
mul();
}
}
void load(){
accum = coder2[coder[in]%100];
if(coder[in]/100==11){
write();
}
if(coder[in]/100==10){
read();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==32){
div();
}
if(coder[in]/100==33){
mul();
}
}
void read(){
resultS += "\n\nEnter an integer.";
result.setText(resultS);
String integer1 = JOptionPane.showInputDialog(
"Enter an integer \n"+
"(a number between -128 \n"+
"and +128 billion).");
coder2[(coder[in])%100] = Integer.parseInt(integer1);
if(coder[in]/100==11){
write();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==32){
div();
}
if(coder[in]/100==33){
mul();
}
}
void write(){
String code2 = "\n\n"+(coder2[(coder[in])%100])+"";
resultS+=code2;
result.setText( resultS );
if(coder[in]/100==10){
read();
}
if(coder[in]/100==20){
load();
}
if(coder[in]/100==21){
store();
}
if(coder[in]/100==30){
add();
}
if(coder[in]/100==31){
sub();
}
if(coder[in]/100==32){
div();
}
if(coder[in]/100==33){
mul();
}
}
public static void main(String[] args){
new cml();
}
}
Any help would be appreciated...