Link to home
Start Free TrialLog in
Avatar of bhuey_ling
bhuey_ling

asked on

how to delete a item in list?

hello!

i have 2 lists, I would like to provide user to delete item in the lists, but the item in the lists have to delete in parallel, means if i select one item from one of the list- list A, The other item from list B which same row with list A also will be highlighted.It also can delete more than one row.

If user press "DELETE", both item will be delete.


hoW to write the code?
thanks
rgds
hl
Avatar of bhuey_ling
bhuey_ling

ASKER

Edited text of question.
r u working with java.awt.List?

what u can do is,

under the delete actionlistener,

//
int[] indexes=listA.getSelectedIndexes();
for(int i=0;i<indexes.length;i++){
   listA.remove(indexes[i]);
   listB.remove(indexes[i]);
}

//

-sgoms
HELLO
do the 2 list has same items?
i assume that both has samle item:)
then code is

public class TList extends Frame implements ActionListener
{public int i;
      private Button b;
      private List l,m;
      public TList()
      {
            setSize(300,300);
            Panel f = new Panel();
f.setLayout(new BorderLayout());
b = new Button("Delete");
b.addActionListener(this);
f.add(BorderLayout.SOUTH,b);
l = new List();
m = new List();
l.add("abc");
l.add("xyz");
l.addMouseListener(new Mous());
            m.add("mmm");
            m.add("nnn");
f.add(BorderLayout.CENTER,l);
            
f.add(BorderLayout.NORTH,m);
f.setVisible(true);
add(f);
                        
}
public void actionPerformed(ActionEvent e)
{
      l.remove(i);
      m.remove(i);
      }
private class Mous extends MouseAdapter
      {
      
public void mouseClicked( MouseEvent e )
{
i = l.getSelectedIndex();
l.remove(i);
m.remove(i);
}
}
      
public static void main(String args[])
{
TList t = new TList();
t.setVisible(true);
            
}
}
instead of actionlistener & mouselistener ..add the specified listener for List.

//create list1, list2 & add items to it

list1.addItemListener(new ItemListener(){
   public void itemStateChanged(ItemEvent e){
      int[] indexes=list1.getSelectedIndexes();
      for(int i=0;i<indexes.length;i++){
         //select the corresponding item in list2
         list2.select(indexes[i]);
         //remove items
         list1.remove(indexes[i]);
         list2.remove(indexes[i]);
      }
   }
};

//

-sgoms
hey sgoms & what if u want to select it using mouse
when u select it with a mouse the itemstate changes from being not selected to selected so an event will be triggered & u can capture that using ItemListnener.
ok sgoms i got it
thanks
hello...

thanks for help ......

sgoms,
well below is my program that had been add ur code:

but got 1 error:

error:
1.Pulse_2.java:128: Type expected.
      listInput.addItemListener(new ItemListener(){

program:
import java.awt.*;
import java.applet.*;

public class Pulse_2 extends Applet
{
      Scrollbar sred;
      Button btnReset, btnDraw, btnSave;
      TextField txtInputVal, txtOutputVal, txtXY;
      Label lblRed, lblOutput, lblInput, lblInputVal, lblOutputVal;
      DisplayCanvas intensityDisplay;
      List listInput, listOutput;
      String INPUT[]= new String [20];
      String OUTPUT[]= new String [20];
      
                  
      public void init(){
            
            listInput=new List(15, true);
            listOutput=new List(15, true);
            
            txtInputVal = new TextField("5.000",3);
            txtOutputVal = new TextField("4.886",3);
            txtXY = new TextField("X,Y",6);
            btnReset = new Button("Reset");
            btnSave = new Button("Save Data");
            btnDraw = new Button("Draw Graph");
            lblRed = new Label("Potentiometer");
            lblOutput = new Label("Output Voltage");
            lblInput = new Label("Input Voltage");
            lblInputVal = new Label("Input Voltage");
            lblOutputVal = new Label("Output Voltage");
            sred = new Scrollbar(Scrollbar.HORIZONTAL, 255, 0, 0, 255);
                        
            intensityDisplay = new DisplayCanvas();
//              graphDisplay = new graphCanvas();
              intensityDisplay.setBackground(Color.lightGray);
//              graphDisplay.setBackground(Color.black);
            
            GridBagLayout gbLayout = new GridBagLayout();
            setLayout(gbLayout);

            GridBagConstraints gbConstraints = new GridBagConstraints();

            gbConstraints.fill = GridBagConstraints.NONE;
            gbConstraints.anchor = GridBagConstraints.WEST;
            gbConstraints.weightx = 10;
            gbConstraints.weighty =10;
            add(lblRed, gbLayout, gbConstraints, 3, 3, 1, 1);

            gbConstraints.fill = GridBagConstraints.BOTH;
            gbConstraints.weightx = 150;
            add(intensityDisplay, gbLayout, gbConstraints, 0, 0, 3, 7);
//            add(graphDisplay, gbLayout, gbConstraints, 3, 0, 1, 7);

            gbConstraints.fill = GridBagConstraints.NONE;
            gbConstraints.weightx = 10;
            add(listInput, gbLayout, gbConstraints, 5, 1, 1, 7);
            add(listOutput, gbLayout, gbConstraints, 6, 1, 1, 7);

            gbConstraints.fill = GridBagConstraints.HORIZONTAL;
            gbConstraints.anchor = GridBagConstraints.CENTER;
            gbConstraints.weightx = 10;
            add(sred, gbLayout, gbConstraints, 3, 4, 2, 1);

            gbConstraints.anchor = GridBagConstraints.WEST;
            add(lblInput, gbLayout, gbConstraints, 3, 0, 1, 1);
            add(txtInputVal, gbLayout, gbConstraints, 4, 0, 1, 1);
            add(lblOutput, gbLayout, gbConstraints, 3, 1, 1, 1);
            add(txtOutputVal, gbLayout, gbConstraints, 4, 1, 1, 1);
            add(txtXY, gbLayout, gbConstraints, 3,5,1,1);
            add(btnReset, gbLayout, gbConstraints,4,5,1,1);
            add(btnDraw, gbLayout, gbConstraints,5,8,1,1);
            add(btnSave, gbLayout, gbConstraints,4,2,1,1);
            add(lblInputVal, gbLayout, gbConstraints,5,0,1,1);
            add(lblOutputVal, gbLayout, gbConstraints,6,0,1,1);
//            graphDisplay.repaint();
      
      }
      
      private void add(Component component, GridBagLayout layout,
            GridBagConstraints constraints, int x, int y, int w, int h)
      {
            constraints.gridx = x;
            constraints.gridy = y;
            constraints.gridwidth = w;
            constraints.gridheight = h;
            layout.setConstraints(component, constraints);
            add(component);
      }
      
            
      public boolean handleEvent(Event evt){      
            if(evt.target instanceof Scrollbar){
            double ipVolt = InputVolt(sred.getValue());
            OutputVolt(ipVolt);      
            return true;
            }
            return super.handleEvent(evt);      
      }
      public boolean action(Event ev, Object arg){
            //most commponents generate ACTION_EVENT
            //we must test the target field to find out which component      
            if(ev.target instanceof TextField){
                        String label = (String)arg;
                        float value;
                        value=Float.valueOf(label).floatValue();
                        if(ev.target==txtInputVal)
                        textInput(1,value);
                        if(ev.target==txtOutputVal)
                        textInput(2,value);
            }
             
                  else if(ev.target instanceof Button){
                        String label =(String)arg;
                        if(label.equals ("Reset"))reset();
                        else if(label.equals("Save Data")){
                              listInput.addItem(""+txtInputVal.getText()+"V");
                              listOutput.addItem(""+txtOutputVal.getText()+"V");
                        }  
                        else if(label.equals("Draw Graph")){
                              Frame f= new Frame();
                              f.show();
                              }       
                  }      
            return true;
      }
      
//ur code
      
      listInput.addItemListener(new ItemListener(){
               public void itemStateChanged(ItemEvent e){
                        int[] indexes=listInput.getSelectedIndexes();
                        for(int i=0;i<indexes.length;i++){
                     //select the corresponding item in list2
                     listOutput.select(indexes[i]);
                     //remove items
                     listInput.remove(indexes[i]);
                     listOutput.remove(indexes[i]);
                  }
               }
      };

//ur code end
      
      public boolean mouseMove(Event e, int x, int y){
            writeXY(x,y);
            return true;
      }
      
      public boolean mouseExit(Event e, int x, int y){
            txtXY.setText("X,Y");
            return true;
      }
      
      private void writeXY(int x, int y){
            txtXY.setText(""+Integer.toString(x)+","+
                  Integer.toString(y));
      
      }

      boolean inrange, normal;      
      public void textInput(int type, double value){
            double Input;
            switch (type){
            case 1: //Input
                  condition1(value);
                  if(inrange){                  
                        int val=(int)(value/5*255);
                        sred.setValue(val);                  
                        OutputVolt(value);
                  }
                  break;
            case 2: //output
                  condition2(value);
                  if(normal){
                        Input=test(value);
                        int val=(int)(Input/5*255);
                        sred.setValue(val);
                        writeText(txtInputVal,Input);
                        OutputVolt(Input);
                  }
                  break;
            }
      }            
            
      private double InputVolt (int ipVal)
      {
            double Val = (double)ipVal/255*5;
            writeText(txtInputVal,Val);
            return Val;
            
      }
      
      public void reset(){
            writeText(txtInputVal,5.000);
            writeText(txtOutputVal,4.886);
            intensityDisplay.setForeground(Color.red);
//            graphDisplay.setXY(5.,5.);
            sred.setValue(255);
            on=true;
      }                        

      boolean on, temp1=true;
      double temp=4.84;      
      private void OutputVolt(double inputVal)
      {      
            double current=(double)inputVal-0.114;
            if(current>=0.144)
            writeText(txtOutputVal,current);
            else writeText(txtOutputVal,0.);
                                                            
            if(current>=4.84)
            {
                  intensityDisplay.setForeground(Color.red);
                  intensityDisplay.repaint();
//                  graphDisplay.setXY(inputVal,5.);
                  on=true;
            }
            
            else
            {
                  double previous=temp ;
                  boolean red=temp1;
                  if(current>previous){
                        if(red){
                              intensityDisplay.setForeground(Color.red);
                              intensityDisplay.repaint();
//                              graphDisplay.setXY(inputVal,5.);                              
                              on=true;
                        }      
                              
                        else{
                              if(current>=3.078){
                                    intensityDisplay.setForeground(Color.red);
                                    intensityDisplay.repaint();
//                                    graphDisplay.setXY(inputVal,5.);
                                    on=true;
                              }
                              
                                    
                              else{      
                                    intensityDisplay.setForeground(Color.black);
                                    intensityDisplay.repaint();
//                                    graphDisplay.setXY(inputVal,0.);
                                    on=false;      
                              }
                        }
                  }
                                    
                  else{
                        if(red){
                              if(current>=1.913){
                                    intensityDisplay.setForeground(Color.red);
                                    intensityDisplay.repaint();
//                                    graphDisplay.setXY(inputVal,5.);
                                    on=true;                                          
                              }      
                              else{
                                    intensityDisplay.setForeground(Color.black);
                                    intensityDisplay.repaint();
//                                    graphDisplay.setXY(inputVal,0.);
                                    on=false;      
                              }
                        }      
                              
                        else{
                              intensityDisplay.setForeground(Color.black);
                              intensityDisplay.repaint();
//                              graphDisplay.setXY(inputVal,0.);
                              on=false;                              
                        }
                  }
            }                  
            
            temp=(double)inputVal-0.114;
            temp1=on;
      }
                                    
      public void condition1(double value1){
            if (value1>=0 && value1<=5)
            inrange=true;
            else{
                  inrange=false;
                  Frame f=new Frame("InfoDialog Test");
                  f.resize(100,100);
                  InfoDialog dlg=new InfoDialog(f,"Danger!",
                            " Invalid Input Voltage.Try Again!");                     
                  dlg.show();
                  reset();
            }
      }
      
      public void condition2(double value2){
            if (value2>=0 && value2<4.98)
            normal=true;
            else{
                  normal=false;
                  Frame f=new Frame("InfoDialog Test");
                  f.resize(100,100);
                  InfoDialog dlg=new InfoDialog(f,"Danger!",
                            " Invalid Output Voltage.Try Again!");                     
                  dlg.show();
                  reset();
            }
      }
      
      private double test(double value){
            double input;
            if (value < 4.886)
            input=value + 0.114;
            else input=5.000;
            return input;
      }
      
      private void writeText(TextField obj, double value){
            value=(double)((int)(1000.*value)/1000.);
            obj.setText(Double.toString(value));
      }
      
      class InfoDialog extends Dialog{
      protected Button button;
      protected Label label;
      
            public InfoDialog(Frame parent, String title,String message){
                  super(parent, title, true);
            
                  this.setLayout(new BorderLayout(15,15));
            
                  Panel p1=new Panel();
                  p1.setLayout(new FlowLayout(FlowLayout.CENTER,15,15));
                  p1.add(label=new Label(message));
                  this.add("North",p1 );
            
                  button=new Button("Okay");
                  Panel p2=new Panel();
                  p2.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15));
                  p2.add(button);
                  this.add("South",p2);
                  this.pack();
            }
      
            public boolean action(Event e, Object arg){
                  if(e.target==button){
                        this.hide();
                        this.dispose();
                        return true;
                  }
                  else return false;
            }

            public boolean gotFocus(Event e, Object arg){
                  button.requestFocus();
                  return true;
            }
      }
      
      class DisplayCanvas extends Canvas{            
            public DisplayCanvas(){
                      setColor(Color.red);
                }
      
              public void setColor(Color colour){
                      setForeground(colour);
                      repaint();
              }  
                                                                                                                                                                                                                                                                                       
              public void paint(Graphics g){
                      g.fillOval(10,20,130,130);
                      g.fillOval(40,200,80,80);
                      g.setColor(Color.blue);
                      g.setFont(new Font("Helvetica", Font.BOLD,12));
                      g.drawString("LED",70,190);
                      g.drawString("Fiber-optic",60,310);
        }
      }
      
//      class graphCanvas extends Canvas{
//            double xg, yg;
//            public graphCanvas(){
//                  setXY(5.,4.89);
//            }
            
//            public void setXY(double xd, double yd){      
//                  xg=xd;
//                  yg=yd;
//                  repaint();
//            }
                  
//            public void paint(Graphics g){
//                  int col, colMax, row;
//                  colMax = (int)(260-(4.870/5*200));
//                  g.setColor(Color.green);
//                  g.drawLine(10,260,210,260);
//                  g.drawLine(10,60,10,260);
//                  
//                  for(int i=10;i<=210;i+=20)
//                  g.drawLine(i,258,i,262);
//                  for(int i=60;i<=260;i+=20)
//                  g.drawLine(8,i,12,i);
                  
//                  g.setColor(Color.white);
//                  g.drawLine(10,260,139,260);    //draw graph
//                  g.drawLine(90,60,210,60);
//                  g.drawLine(90,60,90,260);
//                  g.drawLine(139,60,139,260);
//                  g.drawString("0",10,275);
//                  g.drawString("5",205,275);
//                  g.drawString("INPUT(V)",160,290);
//                  g.drawString("5",10,55);
//                  g.drawString("OUTPUT(V)",10,35);
                  
//                  row=(int)(xg/5*210);
//                  col=(int)(260-(yg/5*200));                  
//                  g.setColor(Color.yellow);
//                  if(row+5>=210)
//                  g.fillOval(210,col-5,5,5);
//                  else g.fillOval(row+5, col-3,5,5);      
//                  }            
//            }

//      class graphFrame extends Frame{
//            
//            graphCanvas graphDisplay;
//            graphDisplay = new graphCanvas();
//             graphDisplay.setBackground(Color.black);
             
//             GridBagLayout gbLayout = new GridBagLayout();
//            setLayout(gbLayout);
//            GridBagConstraints gbConstraints = new GridBagConstraints();
//            gbConstraints.fill = GridBagConstraints.BOTH;
//            gbConstraints.weightx = 150;
//            add(graphDisplay, gbLayout, gbConstraints, 0, 0, 1, 7);
//            }            
                  
      public Insets insets(){
            return new Insets(10, 10, 10, 10);
      }
}
            


thanx

rgds
hl
When you add a Listener using
....addXXXListener(new XXXListener(){
});

you r using an anonymous class declaration. instead of having a class that implements XXXListener & tehn using a instance of that class you declare the class there itself. this needs to be stated inside a method & not outside it.

The following program will compile.
      import java.awt.*;
      import java.applet.*;
      import java.awt.event.*;
      
      public class Pulse_2 extends Applet
      {
      Scrollbar sred;
      Button btnReset, btnDraw, btnSave;
      TextField txtInputVal, txtOutputVal, txtXY;
      Label lblRed, lblOutput, lblInput, lblInputVal, lblOutputVal;
      DisplayCanvas intensityDisplay;
      List listInput, listOutput;
      String INPUT[]= new String [20];
      String OUTPUT[]= new String [20];
      
      
      public void init(){
      
      listInput=new List(15, true);
      listOutput=new List(15, true);
      listInput.addItemListener(new ItemListener(){
          public void itemStateChanged(ItemEvent e){
             int[] indexes=listInput.getSelectedIndexes();
            for(int i=0;i<indexes.length;i++){
                //select the corresponding item in list2
                listOutput.select(indexes[i]);
               //remove items
                listInput.remove(indexes[i]);
                listOutput.remove(indexes[i]);
             }
          }
      });       
      txtInputVal = new TextField("5.000",3);
      txtOutputVal = new TextField("4.886",3);
      txtXY = new TextField("X,Y",6);
      btnReset = new Button("Reset");
      btnSave = new Button("Save Data");
      btnDraw = new Button("Draw Graph");
      lblRed = new Label("Potentiometer");
      lblOutput = new Label("Output Voltage");
      lblInput = new Label("Input Voltage");
      lblInputVal = new Label("Input Voltage");
      lblOutputVal = new Label("Output Voltage");
      sred = new Scrollbar(Scrollbar.HORIZONTAL, 255, 0, 0, 255);
      
      intensityDisplay = new DisplayCanvas();
      //         graphDisplay = new graphCanvas();
              intensityDisplay.setBackground(Color.lightGray);
      //         graphDisplay.setBackground(Color.black);
      
      GridBagLayout gbLayout = new GridBagLayout();
      setLayout(gbLayout);
      
      GridBagConstraints gbConstraints = new GridBagConstraints();
      
      gbConstraints.fill = GridBagConstraints.NONE;
      gbConstraints.anchor = GridBagConstraints.WEST;
      gbConstraints.weightx = 10;
      gbConstraints.weighty =10;
      add(lblRed, gbLayout, gbConstraints, 3, 3, 1, 1);
      
      gbConstraints.fill = GridBagConstraints.BOTH;
      gbConstraints.weightx = 150;
      add(intensityDisplay, gbLayout, gbConstraints, 0, 0, 3, 7);
      // add(graphDisplay, gbLayout, gbConstraints, 3, 0, 1, 7);
      
      gbConstraints.fill = GridBagConstraints.NONE;
      gbConstraints.weightx = 10;
      add(listInput, gbLayout, gbConstraints, 5, 1, 1, 7);
      add(listOutput, gbLayout, gbConstraints, 6, 1, 1, 7);
      
      gbConstraints.fill = GridBagConstraints.HORIZONTAL;
      gbConstraints.anchor = GridBagConstraints.CENTER;
      gbConstraints.weightx = 10;
      add(sred, gbLayout, gbConstraints, 3, 4, 2, 1);
      
      gbConstraints.anchor = GridBagConstraints.WEST;
      add(lblInput, gbLayout, gbConstraints, 3, 0, 1, 1);
      add(txtInputVal, gbLayout, gbConstraints, 4, 0, 1, 1);
      add(lblOutput, gbLayout, gbConstraints, 3, 1, 1, 1);
      add(txtOutputVal, gbLayout, gbConstraints, 4, 1, 1, 1);
      add(txtXY, gbLayout, gbConstraints, 3,5,1,1);
      add(btnReset, gbLayout, gbConstraints,4,5,1,1);
      add(btnDraw, gbLayout, gbConstraints,5,8,1,1);
      add(btnSave, gbLayout, gbConstraints,4,2,1,1);
      add(lblInputVal, gbLayout, gbConstraints,5,0,1,1);
      add(lblOutputVal, gbLayout, gbConstraints,6,0,1,1);
      // graphDisplay.repaint();
      
      }
      
      private void add(Component component, GridBagLayout layout,
      GridBagConstraints constraints, int x, int y, int w, int h)
      {
      constraints.gridx = x;
      constraints.gridy = y;
      constraints.gridwidth = w;
      constraints.gridheight = h;
      layout.setConstraints(component, constraints);
      add(component);
      }
      
      
      public boolean handleEvent(Event evt){
      if(evt.target instanceof Scrollbar){
      double ipVolt = InputVolt(sred.getValue());
      OutputVolt(ipVolt);
      return true;
      }
      return super.handleEvent(evt);
      }
      public boolean action(Event ev, Object arg){
      //most commponents generate ACTION_EVENT
      //we must test the target field to find out which component
      if(ev.target instanceof TextField){
      String label = (String)arg;
      float value;
      value=Float.valueOf(label).floatValue();
      if(ev.target==txtInputVal)
      textInput(1,value);
      if(ev.target==txtOutputVal)
      textInput(2,value);
      }
      
      else if(ev.target instanceof Button){
      String label =(String)arg;
      if(label.equals ("Reset"))reset();
      else if(label.equals("Save Data")){
      listInput.addItem(""+txtInputVal.getText()+"V");
      listOutput.addItem(""+txtOutputVal.getText()+"V");
      }  
      else if(label.equals("Draw Graph")){
      Frame f= new Frame();
      f.show();
      }
      }
      return true;
      }
                  
      public boolean mouseMove(Event e, int x, int y){
      writeXY(x,y);
      return true;
      }
      
      public boolean mouseExit(Event e, int x, int y){
      txtXY.setText("X,Y");
      return true;
      }
      
      private void writeXY(int x, int y){
      txtXY.setText(""+Integer.toString(x)+","+
      Integer.toString(y));
      
      }
      
      boolean inrange, normal;
      public void textInput(int type, double value){
      double Input;
      switch (type){
      case 1: //Input
      condition1(value);
      if(inrange){
      int val=(int)(value/5*255);
      sred.setValue(val);
      OutputVolt(value);
      }
      break;
      case 2: //output
      condition2(value);
      if(normal){
      Input=test(value);
      int val=(int)(Input/5*255);
      sred.setValue(val);
      writeText(txtInputVal,Input);
      OutputVolt(Input);
      }
      break;
      }
      }
      
      private double InputVolt (int ipVal)
      {
      double Val = (double)ipVal/255*5;
      writeText(txtInputVal,Val);
      return Val;
      
      }
      
      public void reset(){
      writeText(txtInputVal,5.000);
      writeText(txtOutputVal,4.886);
      intensityDisplay.setForeground(Color.red);
      // graphDisplay.setXY(5.,5.);
      sred.setValue(255);
      on=true;
      }
      
      boolean on, temp1=true;
      double temp=4.84;
      private void OutputVolt(double inputVal)
      {
      double current=(double)inputVal-0.114;
      if(current>=0.144)
      writeText(txtOutputVal,current);
      else writeText(txtOutputVal,0.);
      
      if(current>=4.84)
      {
      intensityDisplay.setForeground(Color.red);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,5.);
      on=true;
      }
      
      else
      {
      double previous=temp ;
      boolean red=temp1;
      if(current>previous){
      if(red){
      intensityDisplay.setForeground(Color.red);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,5.);
      on=true;
      }
      
      else{
      if(current>=3.078){
      intensityDisplay.setForeground(Color.red);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,5.);
      on=true;
      }
      
      
      else{
      intensityDisplay.setForeground(Color.black);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,0.);
      on=false;
      }
      }
      }
      
      else{
      if(red){
      if(current>=1.913){
      intensityDisplay.setForeground(Color.red);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,5.);
      on=true;
      }
      else{
      intensityDisplay.setForeground(Color.black);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,0.);
      on=false;
      }
      }
      
      else{
      intensityDisplay.setForeground(Color.black);
      intensityDisplay.repaint();
      // graphDisplay.setXY(inputVal,0.);
      on=false;
      }
      }
      }
      
      temp=(double)inputVal-0.114;
      temp1=on;
      }
      
      public void condition1(double value1){
      if (value1>=0 && value1<=5)
      inrange=true;
      else{
      inrange=false;
      Frame f=new Frame("InfoDialog Test");
      f.resize(100,100);
      InfoDialog dlg=new InfoDialog(f,"Danger!",
          " Invalid Input Voltage.Try Again!");    
      dlg.show();
      reset();
      }
      }
      
      public void condition2(double value2){
      if (value2>=0 && value2<4.98)
      normal=true;
      else{
      normal=false;
      Frame f=new Frame("InfoDialog Test");
      f.resize(100,100);
      InfoDialog dlg=new InfoDialog(f,"Danger!",
          " Invalid Output Voltage.Try Again!");    
      dlg.show();
      reset();
      }
      }
      
      private double test(double value){
      double input;
      if (value < 4.886)
      input=value + 0.114;
      else input=5.000;
      return input;
      }
      
      private void writeText(TextField obj, double value){
      value=(double)((int)(1000.*value)/1000.);
      obj.setText(Double.toString(value));
      }
      
      class InfoDialog extends Dialog{
      protected Button button;
      protected Label label;
      
      public InfoDialog(Frame parent, String title,String message){
      super(parent, title, true);
      
      this.setLayout(new BorderLayout(15,15));
      
      Panel p1=new Panel();
      p1.setLayout(new FlowLayout(FlowLayout.CENTER,15,15));
      p1.add(label=new Label(message));
      this.add("North",p1 );
      
      button=new Button("Okay");
      Panel p2=new Panel();
      p2.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 15));
      p2.add(button);
      this.add("South",p2);
      this.pack();
      }
      
      public boolean action(Event e, Object arg){
      if(e.target==button){
      this.hide();
      this.dispose();
      return true;
      }
      else return false;
      }
      
      public boolean gotFocus(Event e, Object arg){
      button.requestFocus();
      return true;
      }
      }
      
      class DisplayCanvas extends Canvas{
      public DisplayCanvas(){
           setColor(Color.red);
           }
      
         public void setColor(Color colour){
           setForeground(colour);
           repaint();
      }  
                                                                                                                                                                                                                                                                                
      
         public void paint(Graphics g){
           g.fillOval(10,20,130,130);
           g.fillOval(40,200,80,80);
           g.setColor(Color.blue);
           g.setFont(new Font("Helvetica", Font.BOLD,12));
           g.drawString("LED",70,190);
           g.drawString("Fiber-optic",60,310);
        }
      }
      
      // class graphCanvas extends Canvas{
      // double xg, yg;
      // public graphCanvas(){
      // setXY(5.,4.89);
      // }
      
      // public void setXY(double xd, double yd){
      // xg=xd;
      // yg=yd;
      // repaint();
      // }
      
      // public void paint(Graphics g){
      // int col, colMax, row;
      // colMax = (int)(260-(4.870/5*200));
      // g.setColor(Color.green);
      // g.drawLine(10,260,210,260);
      // g.drawLine(10,60,10,260);
      //
      // for(int i=10;i<=210;i+=20)
      // g.drawLine(i,258,i,262);
      // for(int i=60;i<=260;i+=20)
      // g.drawLine(8,i,12,i);
      
      // g.setColor(Color.white);
      // g.drawLine(10,260,139,260);    //draw graph
      // g.drawLine(90,60,210,60);
      // g.drawLine(90,60,90,260);
      // g.drawLine(139,60,139,260);
      // g.drawString("0",10,275);
      // g.drawString("5",205,275);
      // g.drawString("INPUT(V)",160,290);
      // g.drawString("5",10,55);
      // g.drawString("OUTPUT(V)",10,35);
      
      // row=(int)(xg/5*210);
      // col=(int)(260-(yg/5*200));
      // g.setColor(Color.yellow);
      // if(row+5>=210)
      // g.fillOval(210,col-5,5,5);
      // else g.fillOval(row+5, col-3,5,5);
      // }
      // }
      
      // class graphFrame extends Frame{
      //
      // graphCanvas graphDisplay;
      // graphDisplay = new graphCanvas();
      // graphDisplay.setBackground(Color.black);
      
      // GridBagLayout gbLayout = new GridBagLayout();
      // setLayout(gbLayout);
      // GridBagConstraints gbConstraints = new GridBagConstraints();
      // gbConstraints.fill = GridBagConstraints.BOTH;
      // gbConstraints.weightx = 150;
      // add(graphDisplay, gbLayout, gbConstraints, 0, 0, 1, 7);
      // }
      
      public Insets insets(){
      return new Insets(10, 10, 10, 10);
      }
      }
hey man pls check ur import statemens u have not added java.awt.event.*;
pls add it & then compile
good luck
ASKER CERTIFIED SOLUTION
Avatar of sgoms
sgoms

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx!
rgds
hl