Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-03-2008, 02:40 AM
Member
 
Join Date: Feb 2008
Posts: 8
JavaInLove is on a distinguished road
Help with drawing strings!
Hello,

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-05-2008, 05:39 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
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.
Code:
public class MyClassName extends JPanel { JTextField textField; String text = ""; protected void paintComponent(Graphics g) { super.paintComponent(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(); repaint(); } }); // add the button to a JPanel and return panel; } public static void main(String[] args) { MyClassName app = new MyTestApp(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(app.getNorth(), BorderLayout.NORTH); f.add(test); // default center section f.add(test.getButtonPanel(), "South"); f.setSize(... f.setLocation(... f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing on aJPanel Djangolo AWT / Swing 1 02-17-2008 03:01 AM
New: Want to understand Drawing... diRisig New To Java 1 02-05-2008 10:13 AM
drawing window BlitzA Advanced Java 0 12-30-2007 07:39 PM
drawing window BlitzA New To Java 0 12-30-2007 06:45 PM
Help with Drawing a line Rgfirefly24 New To Java 1 08-06-2007 10:40 AM


All times are GMT +3. The time now is 03:23 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org