Results 1 to 2 of 2
Thread: Help with drawing strings!
- 02-03-2008, 12:40 AM #1
Member
- Join Date
- Feb 2008
- Posts
- 13
- Rep Power
- 0
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
- 02-05-2008, 03:39 AM #2
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) { 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); } }
Similar Threads
-
drawing window
By BlitzA in forum New To JavaReplies: 1Last Post: 01-15-2009, 12:55 PM -
Drawing on aJPanel
By Djangolo in forum AWT / SwingReplies: 1Last Post: 02-17-2008, 01:01 AM -
New: Want to understand Drawing...
By diRisig in forum New To JavaReplies: 1Last Post: 02-05-2008, 08:13 AM -
drawing window
By BlitzA in forum Advanced JavaReplies: 0Last Post: 12-30-2007, 05:39 PM -
Help with Drawing a line
By Rgfirefly24 in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks