CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jan 2007
    Posts
    18

    [ Beginner ] Code Errors

    Hello Everyone,

    This is the code of 2 seperate panels :
    - the first panel contains 2 buttons + 2 textboxes
    - the second panel contains 3 buttons (Erase, Change, and Exit)
    When we enter some text in the first textbox , if we click on "change"
    the data entered in textbox1 will be sent to textbox2.

    I'm trying this code but unfortunately it is not working. Would someone
    help me find the errors ? Thanks in advance.

    Code:
    package untitled5;
    
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class Echange extends Frame implements ActionListener {
    
      Label l1=new Label("text1");
      TextField t1=new TextField(20);
      Label l2=new Label("text2");
      TextField t2=new TextField(20);
      Button ef=new Button("Effacer");
      Button ech=new Button("Echanger");
      Button fin=new Button("Fin");
    
      public Echange(){
    
        Panel p1=new Panel();
        Panel p2=new Panel();
        GridLayout g=new GridLayout(2,2);
        FlowLayout f=new FlowLayout(1,3);
        p1.setLayout(g);
        p1.add(l1);
        p1.add(t1);
        p1.add(l2);
        p1.add(t2);
        p2.setLayout(f);
        p2.add(ef);
        p2.add(ech);
        p2.add(fin);
        ef.addActionListener(this);
        ech.addActionListener(this);
        fin.addActionListener(this);
        BorderLayout b=new BorderLayout();
        this.setLayout(b);
        this.add("North",p1);
        this.add("Center",p2);
        pack();
        show();
    
      addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent e){
            System.exit(0);
              }});
      public void actionPerformed(ActionEvent e){
         if(e.getSource()==ef){
           t1.setText(" ");
           t2.setText(" ");
           }
         else
             if(e.getSource()==ech){
                String s;
                s=t1.getText();
                t1.setText(t2.getText());
                t2.setText(s);
                }
             else if(e.getSource()==fin){
               System.exit(0);
                   }
             }
    
             }
    
     public static void main(String[] args) {
      new Echange();
    
          }
        }
    Last edited by tima; January 7th, 2007 at 08:04 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
  •  





Click Here to Expand Forum to Full Width

Featured