Help in gui drawing

hi ppl if i want to draw shapes inside a j pane and i want the sizes according to the jpane it self so please help me i want a refrence to how to draw on guis

you can call getSize or getExtents or something like that on the panel, then you will know the size of the canvas

Similar Messages

  • Dear Friends, I am trying to draw a structure in Adobe Illustrator with 3D effect. But I am unable to give it proper shape. Can someone please help me for drawing the similar structure as showed below. I have facing problems in giving 3D effect.

    Dear Friends, I am trying to draw a structure in Adobe Illustrator with 3D effect. But I am unable to give it proper shape. Can someone please help me for drawing the similar structure as showed below. I have facing problems in giving 3D effect.
    Thanks a lot for your great help...

    i made a quick example:
    and what it's made of:
    just shapes and gradients. used a combination of pathfinder and shape builder to get the shapes exact.

  • Please help!! Drawing problem

    Hi all,
    Sorry for bothering for this question but it's important for me to have an answer..
    Well, i created a small graphic interface in which i put some buttons and an area to display Graphics (see Xrect in my code).
    The problem i have is that i can display my graphics in my area but if i come with a window over it, it erases it!!!! What shall i do??
    Thanx in advance, i hope this piece of code will be helpful..
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.lang.*;
    //D�finition de la classe Bio_Window
    public class Bio_Window extends JFrame {
    public Bio_Window () {
    initGUI();
    //Initialisation de la fen�tre de BIOWAY
    public void initGUI () {
    Xrect rect = new Xrect(); //initialisation de la zone de dessin
    rect.setBounds(xrect,yrect,370,340);
    getContentPane().add(rect);
    setVisible(true);
    //methode r�sultante d'un click sur Accept
    public void accept() {
    //Dessin du r�seau repr�sent� dans le fichier
    Graphics g1 = this.getGraphics();
    int x1 = xrect + w2;
    int y1 = yrect+50 + w3;
    g1.setColor(Color.black);
    g1.fillOval(x1,y1,6,6);
    Graphics g2 = this.getGraphics();
    int x2 = xrect + w4;
    int y2 = yrect + 50 + w5;
    g2.setColor(Color.black);
    g2.fillOval(x2,y2,6,6);
    Graphics g3 = this.getGraphics();
    g3.setColor(Color.blue);
    int c = 3;
    g3.drawLine(x1+c,y1+c,x2+c,y2+c);
    //Termine l'application lorsqu'on clique sur la croix...
    protected void processWindowEvent(WindowEvent e) {
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    //class permettant la creation de la zone de dessin
    public class Xrect extends JComponent {
    public Xrect() {
    //methode affichant la zone de dessin
    public void paintComponent(Graphics g) {
    g.setColor(Color.white);
    g.fillRect(0,0,370,340);
    super.paintComponent(g);
    //main
    public static void main (String args[]) {
    new Bio_Window();
    //classe traitant des click de bouton de l'interface
    class Evenement implements ActionListener {
    static final int EDIT = 0;
    static final int DRAW = 1;
    static final int PARAMETERS = 2;
    static final int ACCEPT = 3;
    static final int EXIT = 4;
    static final int RUN = 5;
    static final int ERASE = 6;
    static final int REDRAW = 7;
    Bio_Window ev;
    int id;
    public Evenement (Bio_Window ev, int id) {
    this.ev = ev;
    this.id = id;
    public void actionPerformed(ActionEvent e) {
    switch(id) {
    case EDIT:
    ev.edit();
    break;
    case DRAW:
    ev.draw();
    break;
    case PARAMETERS:
    ev.parameters();
    break;
    case ACCEPT:
    ev.accept();
    break;
    case EXIT:
    System.exit(0);
    break;
    case RUN:
    ev.run();
    break;
    case ERASE:
    ev.erase();
    break;
    case REDRAW:
    ev.accept();
    break;
    }

    It looks like your XRec overrides the paintComponent (g) method, which is the correct way or having the XRec updated when damage is done to your GUI, but your Bio_Window has painting code in the accept() method. This should be moved to a seperate method (for example customDraw(g)). You should then override one of the Bio_Window's painting methods to include the customDraw(g) method. For instance, you may make a
    paint method like this:
    paint (g) {
      paintComponent(g);
      customDraw(g);
      paintBorder(g);
      paintChildren(g);
    }Oh, BTW,
    class x implements ActionListener extends Component
    should be
    class x extends Component implements ActionListener
    Steve

  • Urgent! Need help in GUI!

    Hi, I am doing a small java project and I am expected to code all the GUI I need in just one class file. Can someone help me? My GUI consists of 2 JButtons, 2 JLabels and 1 JTextField. Also I need to have ActionListener for both of the buttons all in just 1 class file. Anyone please help. It is better if you can provide me with some sample coding to view

    That sounds like a very arbitrarily cooked-up requirement. Homework?
    Assuming your class needs to be a component itself, simply add the buttons, labels and fields into it, typically within the constructor.
    If you mean "one source file" then I would advise using an inner class as your ActionListener; you may even want two. You may like to use anonymous classes which, for instance, call methods in your outer class. All of these solutions will produce more than one class file from the single source file.
    If you really do mean "one class file" then you will need your outer class to implement ActionListener and determine from the getActionCommand() or getSource() methods which of the two buttons the event emanated from. It's a less clean way of going about it, but you get your single class file.
    No sample code - if you need further explanation of the above then just Google for the underlined terms.

  • Help with GUI (calling one class from other class)

    Hi everybody,
    I am new at GUI and I need your help..
    I have a JPanel, named "holdAll", layout of which is set to BorderLayout. I have implemented all other JPanels in different class files. For example, I have TopPanel, LeftPanel, etc. as shown below
    LeftPanel myLeft = new LeftPanel();
    holdAll.add(myLeft, BorderLayout.WEST);
    RightPanel myRight = new RightPanel();
    holdAll.add(myRight, BorderLayout.EAST);
    TopPanel myTop = new TopPanel();
    holdAll.add(myTop, BorderLayout.NORTH);
    MiddlePanel myMiddle = new MiddlePanel();
    holdAll.add(myMiddle, BorderLayout.CENTER);
    BottomPanel myBottom = new BottomPanel();
    holdAll.add(myBottom, BorderLayout.SOUTH);
    That works well but I have difficulties in ActionListeners.. For example, in my TopPanel class I have the code below:
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnInsert) {
    int returnVal = fc.showOpenDialog(fc);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    myImage newImage = new myImage(file);
    System.out.println(newImage.myHashCode());
    Here, if I have upload new image, then I have to update the listImage in the LeftPanel class.. But, I could not access the lstImage object in the LeftPanel class from the actionListener event in the TopPanel class.
    What should I do? Is my design poor?

    public class TopPanel extends JPanel implements ActionListener { //it doesn't allow "extends JPanel, Observable"
    JFileChooser fc;
    JButton btnInsert;
    JButton btnDelete;
    public TopPanel() {
    setLayout(new FlowLayout());
    setBorder(BorderFactory.createBevelBorder(1, Color.WHITE, Color.GRAY));
    btnInsert = new JButton("Insert");
    btnDelete = new JButton("Delete");
    JLabel myLabel = new JLabel(" Search : ");
    JTextField txtSearch = new JTextField();
    txtSearch.setColumns(20);
    JToolBar searchToolBar = new JToolBar();
    fc = new JFileChooser();
    btnInsert.addActionListener(this);
    searchToolBar.add(btnInsert);
    searchToolBar.add(btnDelete);
    searchToolBar.add(myLabel);
    searchToolBar.add(txtSearch);
    add(searchToolBar);
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == btnInsert) {
    int returnVal = fc.showOpenDialog(fc);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    *//Here I want to send fc.GetName() to the JList in the LeftPanel*
    my LeftPanel class is below:
    public class LeftPanel extends JPanel{
    public LeftPanel(){
    this.setLayout(new BorderLayout());
    setBorder(BorderFactory.createBevelBorder(1, Color.WHITE, Color.GRAY));
    JPanel pnlButtons = new JPanel();
    JButton btnName = new JButton("Name");
    JButton btnSize = new JButton("Size");
    JButton btnDate = new JButton("Date");
    pnlButtons.add(btnName);
    pnlButtons.add(btnSize);
    pnlButtons.add(btnDate);
    pnlButtons.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    JPanel pnlImage = new JPanel();
    JList lstImage = new JList();
    lstImage.setVisible(true);
    pnlImage.add(new JScrollPane(lstImage));
    add(pnlButtons, BorderLayout.NORTH);
    add(pnlImage, BorderLayout.CENTER);
    Is there any simple way?

  • PLEASE HELP!! Drawing Lines

    Hi, I'm new to Java and i need some help with drawing an asymptotic curve.
    I have tried many times experimenting with g.drawline but I have no idea how to do it !!
    here is an example of what i want to draw:
    http://www.iit.edu/~smart/acadyear/fredstof.gif_
    Can someone please help me?
    I need the code urgently!
    I just need the lines, plain black with a white background
    and it should also be able to be stretched to any size by dragging the corner of the window
    THANK YOU VERY, VERY MUCH.

    http://forum.java.sun.com/thread.jspa?threadID=5258979

  • Need help in GUI

    I need help in coding for GUI
    I have created 4 classes which are car, car4sale,dealer and the GUI.
    in dealer class I have created a hash table and I want my data to be stored in this hash table can any one help me plz
    my GUI should be build on text field.
    But I don't know how can I link the GUI to the classes.
    this is the GUI but not complete.
    package Carsale;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    class Button extends JFrame implements ActionListener {
    private JButton button;
    private JTextField textField;
    public static void main(String[] args){
    Button frame = new Button();
    frame.setSize(400,300);
    frame.createGUI();
    frame.show();
    private void createGUI(){
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container window = getContentPane();
    window.setLayout(new FlowLayout());
    button = new JButton("VRN");
    window.add(button);
    button.addActionListener(this);
    textField = new JTextField(10);
    window.add(textField);
    public void actionPerformed(ActionEvent event) {
    textField.setText("Button clicked");
    }

    In the future, Swing related questions should be posted in the Swing forum.
    Your question does not have enough information to help you. We can't write a GUI for you. You need to write your own and then ask a specific question when you have a problem.
    Start by reading the [url http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]Swing Tutorial which has lots of examples of creating simple GUIs.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.

  • I need help in GUI

    Hi every one..
    I need help in this class. I want to do a modification to the project AddGUI so that it will do subtraction, multiplication and division of two integre numbers, in addition to addition.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GUIAddition extends JFrame {
       private String output;
       private int number1, number2, sum;
       private JLabel number1Label, number2Label, sumLabel;
       private JTextField number1TextField, number2TextField;
       private JButton addButton, exitButton;
       private JTextArea textArea;
       public GUIAddition()   {
       super("Sum of Two Integer Numbers");
    // Create an instance of inner class ActionEventHandler
       ActionEventHandler handler = new ActionEventHandler();
    // set up GUI
       Container container = getContentPane();
       container.setLayout( new FlowLayout() );
       // set up Label Fields and Text Fields for number1
       number1Label = new JLabel( "Number1" );
       number1TextField = new JTextField( 10 );
       number1TextField.addActionListener( handler );
       container.add( number1TextField );
       container.add( number1Label );
       // for number2
       number2Label = new JLabel( "Number2" );
       number2TextField = new JTextField( 10 );
       number2TextField.addActionListener( handler );
       container.add( number2TextField );
       container.add( number2Label );
       // for sum
       sumLabel = new JLabel( "Sum" );
       textArea = new JTextArea( 1,10 );  // only output, no addAction
       textArea.setEditable( false );
       container.add( textArea );
       container.add( sumLabel );
       // set up Add Button
       addButton = new JButton( "Add" );
       addButton.addActionListener( handler );
       container.add( addButton );
       // set up Exit Button
       exitButton = new JButton( "Exit" );
       exitButton.addActionListener( handler );
       container.add( exitButton );
      }// end constructor
    // Display The Sum of the Two Numbers in displayfield
       public void displayAddition() {
           textArea.setText(output);
      }// end display method
       public static void main( String args[] )   {
          GUIAddition window = new GUIAddition();
          window.setSize(500, 100);
          window.setVisible( true );
      }// end main
       private class ActionEventHandler implements ActionListener {
         public void actionPerformed(ActionEvent event) {
           // process Text Fields: number1 and number2 as well as Add Button events
           if (event.getSource() == number1TextField)
               number1 = Integer.parseInt(event.getActionCommand());
           else if (event.getSource() == number2TextField)
               number2 = Integer.parseInt(event.getActionCommand());
           else if (event.getSource() == addButton){
                   sum = number1 + number2;
                   output = "" + sum;
                   System.out.println("The Result of adding number1: " + number1 +
                   " and number2: " + number2 + " is: " + sum);
           // process Exit Button event
           else if (event.getSource() == exitButton) System.exit(0);
    // Display Information
           displayAddition();
         } // end method actionPerformed
       }// end inner class ActionEventHandler
    }  // end Class GUIAddition

    I try to do it for subtraction, but it didn't work correctly.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GUIAddition extends JFrame {
       private String output;
       private int number1, number2, sum, sub;
       private JLabel number1Label, number2Label, sumLabel, subLabel;
       private JTextField number1TextField, number2TextField;
       private JButton addButton, subButton, exitButton;
       private JTextArea textArea;
       public GUIAddition()   {
       super("Sum of Two Integer Numbers");
    // Create an instance of inner class ActionEventHandler
       ActionEventHandler handler = new ActionEventHandler();
    // set up GUI
       Container container = getContentPane();
       container.setLayout( new FlowLayout() );
       // set up Label Fields and Text Fields for number1
       number1Label = new JLabel( "Number1" );
       number1TextField = new JTextField( 10 );
       number1TextField.addActionListener( handler );
       container.add( number1TextField );
       container.add( number1Label );
       // for number2
       number2Label = new JLabel( "Number2" );
       number2TextField = new JTextField( 10 );
       number2TextField.addActionListener( handler );
       container.add( number2TextField );
       container.add( number2Label );
       // for sum
       sumLabel = new JLabel( "Sum" );
       textArea = new JTextArea( 1,10 );  // only output, no addAction
       textArea.setEditable( false );
       container.add( textArea );
       container.add( sumLabel );
       // for sub
       subLabel = new JLabel( "Subtraction" );
       textArea = new JTextArea( 1,10 );  // only output, no addAction
       textArea.setEditable( false );
       container.add( textArea );
       container.add( subLabel );
       // set up Add Button
       addButton = new JButton( "Add" );
       addButton.addActionListener( handler );
       container.add( addButton );
       // set up Sub Button
        subButton = new JButton( "Subtraction" );
       subButton.addActionListener( handler );
       container.add( subButton );
       // set up Exit Button
       exitButton = new JButton( "Exit" );
       exitButton.addActionListener( handler );
       container.add( exitButton );
      }// end constructor
    // Display The Sum of the Two Numbers in displayfield
       public void displayAddition() {
           textArea.setText(output);
      }// end display method
       public static void main( String args[] )   {
          GUIAddition window = new GUIAddition();
          window.setSize(500, 100);
          window.setVisible( true );
      }// end main
       private class ActionEventHandler implements ActionListener {
         public void actionPerformed(ActionEvent event) {
           // process Text Fields: number1 and number2 as well as Add Button events
           if (event.getSource() == number1TextField)
               number1 = Integer.parseInt(event.getActionCommand());
           else if (event.getSource() == number2TextField)
               number2 = Integer.parseInt(event.getActionCommand());
           else if (event.getSource() == addButton){
                   sum = number1 + number2;
                   output = "" + sum;
                   System.out.println("The Result of adding number1: " + number1 +
                   " and number2: " + number2 + " is: " + sum);
           else if (event.getSource() == subButton){
                   sub = number1 - number2;
                   output = "" + sub;
                   System.out.println("The Result of subtraction number1: " + number1 +
                   " and number2: " + number2 + " is: " + sub);
           // process Exit Button event
           else if (event.getSource() == exitButton) System.exit(0);
    // Display Information
           displayAddition();
         } // end method actionPerformed
       }// end inner class ActionEventHandler
    }  // end Class GUIAddition

  • F4 help for GUI

    Hi,
    I need to store a file on the presentation server. For this purpose, I have an icon on the GUI , to download the file from the output screen to the PS.
    I have used the FM 'GUI_DOWNLOAD' for this.
    I need an F4 help, so that when i click on the download icon the menu bar, a popup should come asking for the path on the PS where i want to store the file.
    Can anyone tell me which FM should I call for the popup?

    At the AT SELECTION_SCREEN ON VALUE-REQUEST FOR p_path and code your value help.
      DATA:
        zz_folder   TYPE string.
      CALL METHOD cl_gui_frontend_services=>directory_browse
         CHANGING
           selected_folder = zz_folder
         EXCEPTIONS
           OTHERS          = 0.
    p_path = zz_folder.
    <b>file from application server</b>
    1. F4_DXFILENAME_TOPRECURSION
    This is the FM.
    Reward points,if found useful

  • Help needed on drawing a logo please

    Hi there. I am wondering if someone who is a whiz at using the pen tool in Illustrator can do me a massive favour please. I need this image in a vector format:
    https://dl.dropbox.com/u/110045863/cb3.jpg
    I have been trying myself all day to draw it and have come up hopelessly short, it looks a mess!!
    I've never asked anyone if they could help me out in this way before, I normally try to ask for tips and have a crack at learning myself, but on this one I am up against a tight deadline and can make nothing of it, so would really really appreciate it is someone could help me out please?
    Many thanks if you can.
    John

    You have to read about the pen tool and practice now hwrre as this is not difficult to do it is a bit time consuming perhaps about fifteen minutes and some of these guys here can do it in like 3 to 5 minutes.
    It is several shapes on top of one another if you do not get the paths correct right away you can adjust the curves using the direct select tool and clicking an anchor and adjusting the handles and you can move the nachor points as well.
    You also make shapes for the gradients by copyong the underlying shapes and placig them on top of the under lying shapes using the layers panel for the gradient overlays use a blending mode of Multiply which you assign with the transparency panel read about the transparenc panel as well in the help files.
    Here is the anatomy of the art. Also sty calm you can fix if after you draw if it is a little messy. Yu should probably trace the art though I never trace someone else's art.
    Here are the individual paths (shapes)

  • Can someone help me with drawing text and a custom image in cocoa?

    I am trying to learn how to draw, and when I look at the tutorial, instead of getting straight to the point on how to draw text at a coordinate, it talks about the concepts of how to draw. I get that, but exactly what methods and what objects should I use?
    For instance, the java code:
    +public void drawComponent(Graphics g){+
    +Graphics2D g2 = (Graphics2D) g;+
    +g2.drawString("Hello, World!", 10, 20);+
    draws the good old "Hello, World!" on a line starting 20 pixels down and 10 pixels across. How would I do the same in objective-c in a customized view? Based on the tutorial, I need specify the code in the
    +- (void)drawRect: (NSRect) rect+
    method.
    Also, how would I draw a picture(.gif and .png format)?

    Here's a very basic example:
    - (void)drawRect:(NSRect)rect {
    // draw text
    NSString *myString = @"Hello World";
    NSFont *font = [NSFont boldSystemFontOfSize:24];
    NSColor *color = [NSColor blueColor];
    NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
    font, NSFontAttributeName,
    color, NSForegroundColorAttributeName,
    nil];
    [myString drawAtPoint:NSMakePoint(20, 0) withAttributes:attrs];
    // draw image
    NSImage *myImage = [NSImage imageNamed:@"picture1.png"];
    [myImage drawAtPoint:NSMakePoint(20, 40)
    fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
    Since the above uses the imageNamed convenience method of NSImage, the arg must be the name of an image file you've previously added to the main bundle (Project->Add to Project). The code for a gif would be exactly the same.
    For more details see [Drawing Images into a View|https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Coc oaDrawingGuide/Images/Images.html#//apple_ref/doc/uid/TP40003290-CH208-BCIIBDAD] and [Simple Text Drawing|https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ CocoaDrawingGuide/Text/Text.html#//apple_ref/doc/uid/TP40003290-CH209-SW1] in the +Cocoa Drawing Guide+. Btw, the above is for OS X, since you asked about Cocoa. iPhone code is now called Cocoa Touch, so I hope I guessed the platform right. In case you really wanted iPhone, the code would be quite similar, but you'll need to substitute CGPointMake for NSMakePoint, UIColor for NSColor, UIImage for NSImage, and use a method like [drawAtPoint:forWidth:withFont:minFontSize:actualFontSize:lineBreakMode:baselin eAdjustment:|http://developer.apple.com/iphone/library/documentation/UIKit/Refer ence/NSStringUIKit_Additions/Reference/Reference.html#//appleref/doc/uid/TP40006893-CH3-SW14] for your text. You'll also only need one arg for the [drawAtPoint|http://developer.apple.com/iphone/library/documentation/UIKit/Refe rence/UIImageClass/Reference/Reference.html#//appleref/doc/uid/TP40006890-CH3-SW24] method of UIImage.
    Hope that helps get you started!
    - Ray

  • Need some help with GUI development

    Hi ppl.. I am new to labview and I am currently involved in a testing equipment development. I need some help. firstly I need to know if multi-screen GUI (with icons and stuff)is possible in Labview. Secondly I need to interface the measurements to a database. Would it be possible to create just small executable to perform the measurement part alone and do the rest of database operation using VB. (or would it be advisable to do the whole lot in labview)
    the final sft should look something like this
    screen1 :setup screen... interface with database
    screen2 :actual test and test results
    screen3 :log file creation
    measurement is via daq board and i also need to send some control signals and set up TCP/IP for data transfer.

    Hello.
    I am not completely sure what you mean by "multi-screen", but I am pretty sure that doing the user interface using a tab control will work for you. I have attached an example VI which is a state machine (which in LabVIEW you do with a case structure inside a while loop). Notice how the configuration controls are in the first page of the tab control, associated with state 0 of the state machine, but in the block diagram, they are actually used in state 1 of the state machine. Instead of writing a very long description, I will let you take a look at the code (which I saved in LV 7.0 version). Let me know if you have questions or comments
    Attachments:
    MultiScreenStateMachineExample.vi ‏50 KB

  • Help: flash actionscript drawing application

    Looking for developer help who can develop a project a little further based on Carlos Yanez basic drawing application.  He provides all the source code for the basic application.  I need the exact simple application but the ability to choose a background image from a file on the server as the canvas and I want to save the created image on a server file instead of on the client machine. The ability to change the pencil drawing size would be an additional plus.  I work with php and mysql so I would like to use them to store the file parameters, even as a blob in mysql, along with some additional user (server) defined variables (I can do the php/mysql side if I can get the file there, I understand there is an swf to png ByteArray class that might be able to save on server .   The project is for an opensource group so the final product would need to remain as such, I would be able to pay for the modifications mentioned above.  The source files are available at the links below.  Thank you.
    http://flashtuts.s3.amazonaws.com/080_DrawingApp/Src/preview.html
    http://active.tutsplus.com/tutorials/games/create-a-basic-drawing-application-in-flash/

    2.5 years later, would it be possible to use this application within another and turn on and off the drawing functions when not specifically at this 'function' of the application?
    Possibly by killing the canvas.addEventListener(s) and then setting tham alive again on return to this function.
    Could it easily be made a back end section, on initial fire up if it did not have the stage items, it gave an error.
    Very green to flash. Thanks for ant comments.
    (If Mr Graffiti had added much more, on his quick  job, he would have been in competition with Adobe PaintBrush)
    Thank you

  • Help!  GUI using two buttons

    Hello all:
    I have created a class for reading and writing to a text file on my hard drive. Also, I have created another class for a GUI to use for opening the text file with a button labeled Display. As you will see in the code below, I have created another button labeled Update. I seek to be able to edit and save the text directly in the text area with the Update button after opening the file with the Display button. Any help would be greatly appreciated. Thanks!
    /** Class TextFile */
    import java.io.*;
    public class TextFile
        public String read(String fileIn) throws IOException
            FileReader fr = new FileReader(fileIn);
            BufferedReader br = new BufferedReader(fr);
            String line;
            StringBuffer text = new StringBuffer();
            while((line = br.readLine()) != null)
              text.append(line+'\n');
            return text.toString();
        } //end read()
        public void write(String fileOut, String text, boolean append)
            throws IOException
            File file = new File(fileOut);
            FileWriter fw = new FileWriter(file, append);
            PrintWriter pw = new PrintWriter(fw);
            pw.println(text);
            fw.close();
        } // end write()
    } // end class TextFile
    /** Class TextFileGUI */
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TextFileGUI implements ActionListener
        TextFile tf = new TextFile();
        JTextField filenameField = new JTextField (30);
        JTextArea fileTextArea = new JTextArea (10, 30);
        JButton displayButton = new JButton ("Display");
        JButton updateButton = new JButton ("Update");
        JPanel panel = new JPanel();
        JFrame frame = new JFrame("Text File GUI");
        public TextFileGUI()
            panel.add(new JLabel("Filename"));
            panel.add(filenameField);
            panel.add(fileTextArea);
            fileTextArea.setLineWrap(true);
            panel.add(displayButton);
            displayButton.addActionListener(this);
            panel.add(updateButton);
            updateButton.addActionListener(this);
            frame.setContentPane(panel);
            frame.setSize(400,400);
            frame.setVisible(true);
        } //end TextFileGUI()
        public void actionPerformed(ActionEvent e)
            String t;
            try
                t = tf.read(filenameField.getText());
                fileTextArea.setText(t);
            catch(Exception ex)
                fileTextArea.setText("Exception: "+ex);
            } //end try-catch
        } //end actionPerformed()
    } //end TextFileGUI

    Swing related questions should be posted in the Swing forum.
    You are using the same ActionListener for both buttons, so you need to be able to tell which button was pressed. There are a couple of ways to do this:
    a) use the getSource() method of the ActionEvent and compare the source against your two buttons to see which one was pressed and then invoke the appropriate code.
    Object source = e.getSource();
    if (source == displayButton)
        //  do display processing
    else if (source == updateButton)
        //  do update processingb) Check the action command to determine which button was clicked. This approach is demonstrated in the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/button.html]How to Use Buttons
    Another option is to create separate ActionListeners for each button so there is no confusion
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    class TextAreaLoad
         public static void main(String a[])
              final JTextArea edit = new JTextArea(5, 40);
              JButton read = new JButton("Read some.txt");
              read.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        try
                             FileReader reader = new FileReader( "some.txt" );
                             BufferedReader br = new BufferedReader(reader);
                             edit.read( br, null );
                             edit.requestFocus();
                        catch(Exception e2) { System.out.println(e2); }
              JButton write = new JButton("Write some.txt");
              write.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        try
                             FileWriter writer = new FileWriter( "some.txt" );
                             BufferedWriter bw = new BufferedWriter( writer );
                             edit.write( bw );
                             edit.setText("");
                             edit.requestFocus();
                        catch(Exception e2) {}
              JFrame frame = new JFrame("TextArea Load");
              frame.getContentPane().add( new JScrollPane(edit), BorderLayout.NORTH );
              frame.getContentPane().add(read, BorderLayout.WEST);
              frame.getContentPane().add(write, BorderLayout.EAST);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • Help||||||||how to draw graphs in java

    dear all
    i m new to the java technology.i am at present working on aproject in which i need to draw graphs.these graphs will show the graphs for past one month,past six month and past one year records display.can u suuggest me where to get the help and how to get the sample sorce code for that.thanx
    regards
    sheetal

    There are a couple of Open Source projects for graphing in Java on Sourceforge, try:
    http://sourceforge.net/projects/jopenchart/
    http://sourceforge.net/projects/jfreechart/
    I haven't used them myself, but I intend to look closer in the future...

Maybe you are looking for

  • How can I create a wiki with Adobe Muse?

    I need to create a wiki for a competition I am in, and I want it to look nice. I need HTML code to create the wiki, and all the code needs to be hosted on their website. They have a box that we are supposed to place the HTML code in. When I use the c

  • Win32 error

    after my computer boots up i receive this error c:\users\jackie\AppData\Local\Conduit\ BackgroundContainer\Background Container.dll is not a valid Win32 application. How can I fix this problem?

  • Interactive Reporting:Error reading data of InfoProvider /CRMBW/CSAL_C01

    Hi Forum, I configured an interactive reporting to read interaction record data. When I execute the reporting, I am getting the following error message:               +Error reading the data of InfoProvider /CRMBW/CSAL_C01+              +No destinati

  • Application crash with Lexmark X63/ Win2000

    When printing any report longer than one page, the report printer aborts and control does not return to Oracle Forms. The forms application must be killed by the task manager. Running the reports from the report builder has the same result, and repor

  • Hi,i have problems with the battery of my iphone 4s

    hi,i have problems with the battery of my iphone 4s