Re: Can't compile (text to graphic window)
From: Mike B (mrcics2000-news-nomail_at_nomail.yahoo.com)
Date: 11/28/04
- Next message: Frances Del Rio: "case sensitivity in strings..."
- Previous message: JS: "Can't compile (text to graphic window)"
- In reply to: JS: "Can't compile (text to graphic window)"
- Next in thread: KiLVaiDeN: "Re: Can't compile (text to graphic window)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 28 Nov 2004 15:03:09 -0600
JS <dsa.@asdf.com> wrote:
> 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?
>
You should sharpen up a little bit. You call a method "repositionSentence",
but you actually have amethod "positionSentence"
-- Mike B
- Next message: Frances Del Rio: "case sensitivity in strings..."
- Previous message: JS: "Can't compile (text to graphic window)"
- In reply to: JS: "Can't compile (text to graphic window)"
- Next in thread: KiLVaiDeN: "Re: Can't compile (text to graphic window)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|