Results 1 to 2 of 2
  1. #1
    JavaInLove is offline Member
    Join Date
    Feb 2008
    Rep Power

    Default Help with drawing strings!


    to be honest am quite a newbie to this forum and to java aswell despite my love with java programming. I have searched this entire part of forum and still cant find an answer to my query.

    Im planning to write a program (just for fun & practice) which can draw strings. Ive looked up few sources which they tell me to use a graphics package such as awt/swing. Plus some of its classes and methods such as:
    paint/paintcomponent, drawstrings etc...
    But the problem is i dont know where to start?

    My program must be able to draw strings effectively and hopefully can draw strings from input aswell by taking in from keyboard. To do that i will click on a button and then it draws the inputted string to program.

    my mainly qs are:

    how & where do i start?
    should i use packages?
    AWt? or SWING?
    Application? or Applet???
    how do i draw from input by clicking on buttons?

    * - i have read over many tutorials/ notes and some websites and books + still cant help myself to solve this solution.

    Many thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    how & where do i start?
    There are many ways to do this. On possibility is shown below in pseudocode.
    should i use packages?
    Yes, you will need to import a few.
    AWt? or SWING?
    Swing is easier and more fun. The tutorial examples use Swing.
    Application? or Applet???
    Your choice. Applications are easy enough to start with. Some prefer applets.
    how do i draw from input by clicking on buttons?
    Say, for an application, you could put something like this together to get started.
    Java Code:
    public class MyClassName extends JPanel {
        JTextField textField;
        String text = "";
        protected void paintComponent(Graphics g) {
            float x = whereever
            float y = you prefer
            g.drawString(text, x, y);
        private JPanel getNorth() {
            textField = new JTextField(numCols);
            // add this to a panel and
            return panel
        private JPanel getButtonPanel() {
            JButton button = new JButton("your_string");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    text = textField.getText();
            // add the button to a JPanel and
            return panel;
        public static void main(String[] args) {
            MyClassName app = new MyTestApp();
            JFrame f = new JFrame();
            f.add(app.getNorth(), BorderLayout.NORTH);
            f.add(test);  // default center section
            f.add(test.getButtonPanel(), "South");

Similar Threads

  1. drawing window
    By BlitzA in forum New To Java
    Replies: 1
    Last Post: 01-15-2009, 01:55 PM
  2. Drawing on aJPanel
    By Djangolo in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2008, 02:01 AM
  3. New: Want to understand Drawing...
    By diRisig in forum New To Java
    Replies: 1
    Last Post: 02-05-2008, 09:13 AM
  4. drawing window
    By BlitzA in forum Advanced Java
    Replies: 0
    Last Post: 12-30-2007, 06:39 PM
  5. Help with Drawing a line
    By Rgfirefly24 in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts