Variables and classes in Java

Discussion in 'Programming' started by Dazed_and_confused, Mar 31, 2006.

  1. #1
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    
    public class A2P3 extends Applet implements AdjustmentListener,ActionListener {
    
      Scrollbar scrb;
      int i;
      String s;
      Button b1;
      public String baction;
      Label l1;
      Graphics g;
    
      public void init(){
        scrb=new Scrollbar(Scrollbar.HORIZONTAL, 10,10,1,110);
        add(scrb);
        scrb.addAdjustmentListener(this);
        b1=new Button("Draw Line");
        add(b1);
        b1.addActionListener(this);
        l1=new Label("Current Value is    ");
        add(l1);
      }
      public void adjustmentValueChanged(AdjustmentEvent e)
      {
        i=e.getValue();
        l1.setText("Current Value is "+i);
      }
      public void actionPerformed(ActionEvent e) {
         baction = e.getActionCommand();
      }
      public void paint(Graphics g)
      {
         if (baction=="Draw Line")
        g.drawLine(10,40,i,40);
       }
    }
    Code (markup):
    On clicking the button "Draw Line", i want the prg to draw a line, with width the value of the scrollbar.
    Any idea whats going wrong ?
     
    Dazed_and_confused, Mar 31, 2006 IP
  2. QiSoftware

    QiSoftware Well-Known Member

    Messages:
    805
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    158
    #2
    This line is incorrect ...

    if (baction=="Draw Line")

    Q...
     
    QiSoftware, Apr 11, 2006 IP