Can't compile (text to graphic window)
From: JS (dsa._at_asdf.com)
Date: 11/28/04
- Next message: Mike B: "Re: Can't compile (text to graphic window)"
- Previous message: Mike B: "Re: GMail"
- Next in thread: Mike B: "Re: Can't compile (text to graphic window)"
- Reply: Mike B: "Re: Can't compile (text to graphic window)"
- Reply: KiLVaiDeN: "Re: Can't compile (text to graphic window)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 28 Nov 2004 22:00:13 +0100
The following code is supposed to print two text strings in a graphic
window.
I get the following error message when I try to compile the code below:
Error: cannot resolve symbol
symbol : method repositionSentence (int,int)
location: class MyWriter
Here is the code:
import java.awt.*;
import javax.swing.*;
public class MyWriter extends JPanel
{ private int width;
private int height;
private String sentence = "";
private int x_position;
private int y_position;
public MyWriter(int w, int h)
{ width = w;
height = h;
x_position = width / 5;
y_position = height / 2;
JFrame my_frame = new JFrame();
my_frame.getContentPane().add(this);
my_frame.setTitle("MyWriter");
my_frame.setSize(width, height);
my_frame.setVisible(true);
}
public void paintComponent(Graphics g)
{ g.setColor(Color.red);
g.drawString(sentence, x_position, y_position);
}
public void writeSentence(String s)
{ sentence = s;
this.repaint();
}
public void positionSentence(int new_x, int new_y)
{ x_position = new_x;
y_position = new_y;
this.writeSentence(sentence);
}
}
class AnotherExample
{ public static void main(String[] args)
{ MyWriter writer = new MyWriter(300, 200);
String s = JOptionPane.showInputDialog("Please type some text:");
writer.writeSentence(s);
s = JOptionPane.showInputDialog("Try it again:");
writer.writeSentence(s);
writer.repositionSentence(0, 190);
writer.writeSentence(s + s);
}
}
Why will it not compile?
JS
- Next message: Mike B: "Re: Can't compile (text to graphic window)"
- Previous message: Mike B: "Re: GMail"
- Next in thread: Mike B: "Re: Can't compile (text to graphic window)"
- Reply: Mike B: "Re: Can't compile (text to graphic window)"
- Reply: KiLVaiDeN: "Re: Can't compile (text to graphic window)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|