Can't compile (text to graphic window)

From: JS (dsa._at_asdf.com)
Date: 11/28/04


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



Relevant Pages

  • Re: Cant compile (text to graphic window)
    ... > I get the following error message when I try to compile the code ... > public class MyWriter extends JPanel ... > {private int width; ... > public void paintComponent ...
    (comp.lang.java.help)
  • Re: constructor problem
    ... > compile because it's riddled with syntax errors. ... /*This is the tester class for testing the specialAccount2 object ... private String customerName; ... public void setAmountOwing{ ...
    (comp.lang.java.help)
  • Re: WebService Problem
    ... > I am creating webservice DocManager to store documents.I have a method ... > where path is path of file on server and stream is stream of document. ... compile the client it gives compile time error ... > public void Uploadfile ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • 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)