Back to index

wims  3.65+svn20090927
Question.java
Go to the documentation of this file.
00001 package rene.dialogs;
00002 
00003 import java.awt.FlowLayout;
00004 import java.awt.Frame;
00005 import java.awt.Panel;
00006 import java.awt.event.ActionListener;
00007 
00008 import rene.gui.ButtonAction;
00009 import rene.gui.CloseDialog;
00010 import rene.gui.Global;
00011 import rene.gui.MyLabel;
00012 import rene.gui.MyPanel;
00013 
00024 public class Question extends CloseDialog 
00025     implements ActionListener
00026 {      public int Result;
00027        Object O;
00028        Frame F;
00029        public static int NO=0,YES=1,ABORT=-1;
00030        public Question (Frame f, String c, String title, Object o, 
00031               boolean abort, boolean flag)
00032        {      super(f,title,flag);
00033               F=f;
00034               Panel pc=new MyPanel();
00035               FlowLayout fl=new FlowLayout();
00036               pc.setLayout(fl);
00037               fl.setAlignment(FlowLayout.CENTER);
00038               pc.add(new MyLabel(" "+c+" "));
00039               add("Center",pc);
00040               Panel p=new MyPanel();
00041               p.setLayout(new FlowLayout(FlowLayout.RIGHT));
00042               p.add(new ButtonAction(this,Global.name("yes"),"Yes"));
00043               p.add(new ButtonAction(this,Global.name("no"),"No"));
00044               if (abort) p.add(new ButtonAction(this,Global.name("abort"),"Abort"));
00045               add("South",p);
00046               O=o;
00047               pack();
00048        }
00049        public Question (Frame f, String c, String title, Object o, boolean flag)
00050        {      this(f,c,title,o,true,flag);
00051        }
00052        public Question (Frame f, String c, String title)
00053        {      this(f,c,title,null,true,true);
00054        }
00055        public Question (Frame f, String c, String title, boolean abort)
00056        {      this(f,c,title,null,abort,true);
00057        }
00058        public void doAction (String o)
00059        {      if (o.equals("Yes"))
00060               {      tell(this,O,YES);
00061               }
00062               else if (o.equals("No"))
00063               {      tell(this,O,NO);
00064               }
00065               else if (o.equals("Abort"))
00066               {      tell(this,O,ABORT);
00067                      Aborted=true;
00068               }
00069        }
00073        public void tell (Question q, Object o, int f)
00074        {      Result=f;
00075               doclose();
00076        }
00080        public boolean yes ()
00081        {      return Result==YES;
00082        }
00083        public int getResult ()
00084        {      return Result;
00085        }
00086 }