Re: Can't compile (text to graphic window)

From: Mike B (mrcics2000-news-nomail_at_nomail.yahoo.com)
Date: 11/28/04


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 


Relevant Pages

  • Cant compile (text to graphic window)
    ... I get the following error message when I try to compile the code below: ... {private int width; ... public void paintComponent ...
    (comp.lang.java.help)
  • Weird Problem in using MouseListener
    ... public class MouseInputTester extends java.applet.Applet { ... private int mouseX; ... public void mousePressed{ ... paint, ...
    (comp.lang.java)
  • Weird Problem in using MouseListener
    ... public class MouseInputTester extends java.applet.Applet { ... private int mouseX; ... public void mousePressed{ ... paint, ...
    (comp.lang.java.programmer)
  • Re: Multi-Threading problem
    ... private int seconds=0; ... private void secondsThread() { ... final MyClock myClock=new MyClock; ... public void run ...
    (comp.lang.java.programmer)
  • Re: Problems adding a timer
    ... > private Button PushButton1; ... > public void paint{ ... > private int x; ...
    (comp.lang.java.programmer)