[program-java] Re: Dialog boxes yet again

  • From: "Corbett, James" <James.Corbett@xxxxxxxxxxxxx>
  • To: "'program-java@xxxxxxxxxxxxx'" <program-java@xxxxxxxxxxxxx>
  • Date: Fri, 8 Jul 2011 08:07:45 -0400

Roger:

I was assuming that you were indeed using Eclipse as your IDE. In my examples 
you could use them in any IDE as long as the SWT.jar's were some how part of 
your library.

Jim

________________________________
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Roger Woolgrove
Sent: July 7, 2011 18:49
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Dialog boxes yet again

Hi Jim,

thanks for the speedy response.  I'll give this a try in the next few days to 
see what is what.
However, the first thing I've noticed is the use of eclipse in the import 
statements.  Should this still work even though I am not using eclipse at this 
time yet it is installed on my machine?

Cheers

Roger


----- Original Message -----
From: Corbett, James<mailto:James.Corbett@xxxxxxxxxxxxx>
To: 'program-java@xxxxxxxxxxxxx'<mailto:'program-java@xxxxxxxxxxxxx'>
Sent: Thursday, July 07, 2011 5:24 PM
Subject: [program-java] Re: Dialog boxes yet again

Roger:

Straight away, dump the SWING in favour of SWT. Purely on it's own SWT is 
accessible. Eclipse is using the Standard Widget Tool Kit for building its GUI.

...I have found that accessibility with SWING is always an after thought. Try 
this out:

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class ComboDemo {

 public static Display myDisplay;
 public static boolean internalCall = false;

 public static void main(String[] args) {
  internalCall = true;
  myDisplay = new Display();
  ComboDemo cd = new ComboDemo();
  cd.runDemo(myDisplay);
 }

 public void runDemo(Display display) {
  myDisplay = display;
  Shell shell = new Shell(display);
  shell.setSize(300,300);
  shell.setText("Combo Demo");

  Combo combo1 = new Combo(shell, SWT.DROP_DOWN|SWT.READ_ONLY);
  combo1.setItems(new String[] {"One","Two","Three"});
  combo1.select(0);
  combo1.setLocation(0,0);
  combo1.setSize(100,20);

  Combo combo2 = new Combo(shell, SWT.SIMPLE);
  combo2.setItems(new String[] {"Red","Green","Blue","Yellow"});
  combo2.setBounds(50,50,200,150);
  combo2.select(1);

  Combo combo3 = new Combo(shell, SWT.DROP_DOWN);
  combo3.setLocation(200,0);
  combo3.setSize(50,50);

  shell.open();

  while(!shell.isDisposed()){
  if(!display.readAndDispatch())
   display.sleep();
  }
  if (internalCall) display.dispose();
 }
}
Note that there isn't anything specific to making this class accessible, no 
need of special listeners, no Access Bridge.

If you are happy with this I know where you can find tonnes of demos. This is 
how I got my start in accessible Java programming.

...as for the dialog box, I'm afraid you are recreating the wheel.

/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.swt.snippets;

/*
* FormLayout example snippet: create a simple dialog using form layout
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*/
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;

public class Snippet65 {

public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
Label label = new Label (shell, SWT.WRAP);
label.setText ("This is a long text string that will wrap when the dialog is 
resized.");
List list = new List (shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
list.setItems (new String [] {"Item 1", "Item 2"});
Button button1 = new Button (shell, SWT.PUSH);
button1.setText ("OK");
Button button2 = new Button (shell, SWT.PUSH);
button2.setText ("Cancel");

final int insetX = 4, insetY = 4;
FormLayout formLayout = new FormLayout ();
formLayout.marginWidth = insetX;
formLayout.marginHeight = insetY;
shell.setLayout (formLayout);

Point size = label.computeSize (SWT.DEFAULT, SWT.DEFAULT);
final FormData labelData = new FormData (size.x, SWT.DEFAULT);
labelData.left = new FormAttachment (0, 0);
labelData.right = new FormAttachment (100, 0);
label.setLayoutData (labelData);
shell.addListener (SWT.Resize, new Listener () {
public void handleEvent (Event e) {
Rectangle rect = shell.getClientArea ();
labelData.width = rect.width - insetX * 2;
shell.layout ();
}
});

FormData button2Data = new FormData ();
button2Data.right = new FormAttachment (100, -insetX);
button2Data.bottom = new FormAttachment (100, 0);
button2.setLayoutData (button2Data);

FormData button1Data = new FormData ();
button1Data.right = new FormAttachment (button2, -insetX);
button1Data.bottom = new FormAttachment (100, 0);
button1.setLayoutData (button1Data);

FormData listData = new FormData ();
listData.left = new FormAttachment (0, 0);
listData.right = new FormAttachment (100, 0);
listData.top = new FormAttachment (label, insetY);
listData.bottom = new FormAttachment (button2, -insetY);
list.setLayoutData (listData);

shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}

Here's the link....

http://www.eclipse.org/swt/snippets/

________________________________
From: program-java-bounce@xxxxxxxxxxxxx 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Roger Woolgrove
Sent: July 7, 2011 11:55
To: program-java@xxxxxxxxxxxxx
Subject: [program-java] Re: Dialog boxes yet again

Hi Jim,

Below is a class which I am currently developing that I can have certain 
funtions available when writing programs.  The class RawFuntions is far from 
complete.  The class will comprise static methods and maybe instance methods 
but for the moment I am working on static methods to give me dialog boxes.  
Instead of writing lots of code, I want to use code reuse therefore I am hoping 
to write methods that will interact with my screen reader that will work as 
follows:
RawFunctions.alert(String aString);
aString will be displayed in an alert box with an OK button.
RawFunctions.confirm(String aString);
displays aString and 2 buttons Yes/No which returns a boolean True/False 
dependant on selection.
RawFunctions.request(String aString);
displays aString and 2 buttons, OK/Cancel.  OK will return a String as entered 
into the text field and Cancel will return null.
RawFunctions.request(String aString, String bString);
as above yet places bString in the text field as a default response.
RawFuntions.choose(String aString, Set<String> aSet);
displays aString and offers a number of buttons equal to the size of aSet with 
each button marked by the element in aSet.  Also displays Cancel button.  
Returns the String of aSet selected by the button pressed or null for cancel.

The first issue is that I am still slowly working my way through the 
introduction to Eclipse and am therefore using BlueJ which I know is limited 
yet I happen to know that it is possible.
Number 2 is the accessibility and I understand something that I need to use 
listener or something though I haven't got that far yet as I want to get them 
to work before going onto the next step.
Third is the compiler which will not compile as I believe frame is not 
recognised as per the compiler information given below the class.
Fourth and finally for now is finding out where to look.  I have searched the 
web, the java doc and all and am completely at a loss.

import javax.swing.*;
import java.awt.Component.*;
import java.awt.Container.*;
import java.awt.Window.*;
import java.awt.Frame.*;
import java.awt.*;
import javax.swing.JComponent.*;
import javax.swing.JOptionPane.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import ou.*;
/**
* @author Roger Woolgrove
 * @version v1.0 14May2011
 */
public class RawFunctions
{
            /* instance variables */
            public static Frame frame = new Frame();

            /**
             * Default constructor for objects of class RawFunctions
             */
            public RawFunctions()
            {
                        super();
            }


            /* class methods */
   /**
    * creates dialog box with alert message
    */
   public static void alert(String aString)
   {
      JOptionPane.showMessageDialog(null, aString, "Alert", 
JOptionPane.ERROR_MESSAGE);
   }

   /**
    * creates dialog and returns boolean value to argument string
    */
   public static boolean confirm(String aString)
   {
      boolean checkString;
      int anAnswer = JOptionPane.showConfirmDialog(null,
aString, "Confirm", JOptionPane.YES_NO_OPTION);
      if (anAnswer == 1)
      {
         checkString = false;
      }
      else
      {
         checkString = true;
      }
      return checkString;
   }

   /**
    * used to define methods until resolved when
    * methods are added to own method block
    */
   public static void checkDialog()
   {
      JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be 
green.");
JOptionPane.showMessageDialog(frame,
    "Eggs are not supposed to be green.",
    "Message");
JOptionPane.showMessageDialog(frame,
    "Eggs are not supposed to be green.",    "Inane warning",     
JOptionPane.WARNING_MESSAGE);
JOptionPane.showMessageDialog(frame,
    "Eggs are not supposed to be green.",
    "Inane error",
    JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(frame,
    "Eggs are not supposed to be green.",
    "A plain message",
    JOptionPane.PLAIN_MESSAGE);


   }

}

The information that I am receiving from the compiler is as follows:
cannot find symbol - method 
showMessageDialog(java.awt.Frame,java.lang.String,java.lang.String)

Any guidance you can give will be welcomed.
   public static void alert(String aString)
works as required except for the accessibility

   public static boolean confirm(String aString)
works as desired except for accessibility

   public static void checkDialog()
this method contains several methods taken from JOptionPane that I am trying to 
get to work.  The first in this block seems to compile and work except that as 
with the previous 2 methods, there is no feedback from my screen reader as to 
whether I am on the OK button.  alt + O works though not ideal.

If this needs a conversation, I can be reached on Skype at:
rawoolgrove.

Many thanks

Roger


----- Original Message -----
From: Corbett, James<mailto:James.Corbett@xxxxxxxxxxxxx>
To: 'program-java@xxxxxxxxxxxxx'<mailto:'program-java@xxxxxxxxxxxxx'>
Sent: Monday, July 04, 2011 3:51 PM
Subject: [program-java] Re: Dialog boxes yet again

Roger:

Just back again so don't beat me up just yet. What dialog boxes are your 
problems associated with?

Jim

________________________________
From: 
program-java-bounce@xxxxxxxxxxxxx<mailto:program-java-bounce@xxxxxxxxxxxxx> 
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Roger Woolgrove
Sent: June 25, 2011 08:19
To: JavaProgramming
Subject: [program-java] Dialog boxes yet again

Hi all,

I'm having terrible issues with dialog boxes in general.  The kind of problem 
is all over the place.  could someone please give me a correctly syntaxed 
example of a class from import to the end right brace of a class which has 
examples of each type of dialog box.  I cannot make much sense of the java doc 
and am probably missing something simple.

Many thanks

roger


Other related posts: