Simple JAVA Program Problems

Joined
Aug 6, 2008
Messages
1
Reaction score
0
Hello-
I'm trying to write two simple programs and I keep getting the same errors for both. I was hoping someone could tell me what I was doing wrong :oops:

The first program is to create a box that listens to mouse behavior.
The error message i got was:

OkCancel.java:15: cannot find symbol
symbol : class MessagePanel
location: class OkCancel
MessagePanel message = new MessagePanel();
^ ^

The program is:

import javax.swing.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;

class OkCancel extends JFrame{
//JPanel panel = new JPanel();
private JButton btnOK = new JButton("OK");
private JButton btnCancel = new JButton("Cancel");
String messages = " ";
messagePanel message = new messagePanel();

public OkCancel(){
setLayout(new FlowLayout());
message.setBackground(Color.red);
message.setCentered(true);
add(btnOK);
add(message);

add(btnCancel);



btnOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
message.setMessage("You have clicked the ok button\n");
//add(message);
}
});

btnCancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
message.setMessage("You have clicked the Cancel button\n");
//add(message);
}
});



}




public static void main(String[] args){
OkCancel frame = new OkCancel();
frame.setTitle("OkCancel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,600);
frame.setVisible(true);
}
}

The second one is to create a text box that can be shifted with arrows, and I got the same error pretty much.
java:8: cannot find symbol
symbol : class MessagePanel
location: class ButtonDemo
protected MessagePanel messagePanel
^

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

public class ButtonDemo extends JFrame {

protected MessagePanel messagePanel
= new MessagePanel ("Welcome to Java");

private JButton jbtLeft =new JButton("<=");
private JButton jbtRight=new JButton("=>");

public static void main(String[] args) {
ButtonDemo frame = new ButtonDemo();
frame.setTitle("ButtonDemo");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250, 100);
frame.setVisible(true);
}

public ButtonDemo(){
messagePanel.setBackground(Color.cyan);

JPanel jpButtons = new JPanel();
jpButtons.setLayout(new FlowLayout());
jpButtons.add(jbtLeft);
jpButtons.add(jbtRight);
jbtLeft.setMnemonic('L');
jbtRight.setMnemonic('R');



jbtLeft.setIcon(new ImageIcon("images/left.gif"));
jbtRight.setIcon(new ImageIcon("images/right.gif"));
jbtLeft.setToolTipText("Move message to left");
jbtRight.setToolTipText("Move message to right");

setLayout(new BorderLayout());
add(messagePanel, BorderLayout.CENTER);
add(jpButtons, BorderLayout.SOUTH);

jbtLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
messagePanel.moveLeft();

jbtRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
messagePanel.moveRight();
}
});
}
});}}

I'm not very good with Java, and it's driving me nuts that I can't figure it out. I'd appreciate any thoughts on it, Thanks! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top