0

OK no sorry, just me being a fool I don't need this functionality at all

character += String.format("%s", KeyEvent.getKeyText(event.getKeyCode()));
            textArea.setText(character);

because I'm typing inside the textArea so no need to copy character by character. Now I need to change the background color of the corresponding key on the virtual keyboard, will post when that's done, sorry, got a little confused

Edited by Violet_82

0

Right, so unfortunately I'm having problems with getting constants out of key I press on the actual keyboard. I first used method getKeyCode(), which works but brings up the the keycode number, whereas I need to constants, the same I used in my map, si I soon realized that I needed getExtendedKeyCode(). The thing is that I can't get the latter to work, I get a symbol not found error, which is a bit worrying. So I went onto the net, onto the API trying to understand why that method doesn't work, and the only possible explanation is that maybe, since that method has been available since Java 7 (and I'm using java 7), somehow I'm not specifying I'm using java 7 or something weird like that. The method returns a int as does getKeyCode().
I tried different combinations, event.getExtendedKeyCode(), KeyEvent.getExtendedKeyCode() - admittedly not sure what the difference is between calling the method on event. or calling it on KeyEvent., but no joy
Relevant code below (I commented out the line using getKeyCode())

...
    public TouchType(){//constructor
        ...
        super("Typing application");
        KeyHandler handler = new KeyHandler();
        for(JButton currentButton:mp.values()){
            currentButton.addKeyListener(handler);
        }       
    }//end of constructor
    //private class for event handling
    private class KeyHandler implements KeyListener{
        public void keyPressed(KeyEvent event){
            //character = String.format("%s", event.getKeyCode());//get the constant            
            character = String.format("%s", event.getExtendedKeyCode());
            textArea.setText(character);
        }
        public void keyReleased(KeyEvent event){

        }
        public void keyTyped(KeyEvent event){

        }
    }

Edited by Violet_82

0

The pressed and released events give you a VK wich is a reference to a physical key on the keyboard. You can use those (via getKeyCode, not extended key code) for the map lookup to get the corresponding button. That's not the same as the typed event that gives you an actual Unicode character.
Those VKs are useless to you in updating the text area, anlthough they are the ones you need to highlight the key button on the screen. The chars in KEY_TYPED are useless to you in highlighting buttons, although they are the ones you need to add to the text area.

If that's stuill confusing, just think about an sequence like

press shift
press 8
release 8
release shift

The pressed/released events give you the VKs for the shift and 8 keys to highlight and unhighlight, but its the typed event generated in the middle of that sequence that gives you the asterisk to display in the text area

Edited by JamesCherrill

0

Thanks for the explanation JamesCherrill. OK, so let's gloss over what I was trying to do before, clearly wrong. My understanding of the whole thing was this. Let's just forget about event handlings for just one second: when the GUI is displayed I can freely type in the textArea using my actual keyword, with no event handling occurring, as you would be able to type in a normal text field, so, I would have thought, I don't need to capture any typed event (so I left the method public void keyTyped{} empty), I'm only interested in keyPressed() and keyReleased(), correct?
I've made a few changes to the code, and added a variable to hold the button whose background needs to change, and an int variable to hold the key code: here is th code excerpt with the changes, but the colour isn't changing...

import java.awt.Color;
public class TouchType extends JFrame{  
    private Color originalColour;//to get the background of the original colour before changing it
    private int theChar;//to hold the vk constant
    private JButton buttonToHighlight;//button to hightlight

    ...
    public TouchType(){//constructor
        ...
        super("Typing application");
        KeyHandler handler = new KeyHandler();
        for(JButton currentButton:mp.values()){//going through all the buttons
            currentButton.addKeyListener(handler);//add listeners to buttons
            originalColour = currentButton.getBackground();//get the original colour of the button, don't need to do that here, just for testing
        }       
    }//end of constructor
    //private class for event handling
    private class KeyHandler implements KeyListener{
        public void keyPressed(KeyEvent event){
            theChar = event.getKeyCode();//get keyCode
            buttonToHighlight = mp.get(theChar);//get clicked button            
            buttonToHighlight.setBackground(Color.GREEN);//change button colour
        }
        public void keyReleased(KeyEvent event){
            buttonToHighlight.setBackground(originalColour);//set back colour
        }
        public void keyTyped(KeyEvent event){

        }
    }
}
0

I think I may have said right a the beginning - Swing keyboard handing is surprisingly hard, mostly because you need to know where the keyboard focus will be, (because that's where you need to add your listener). If your text area is responding to keyboard input, then it's the component that has the focus, so that's the component you need to add the listener to. But even then, if the use clicks somewhere else that may change the focus.
See https://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html
for more info on this topic.

There is a solution to the focus problem... see http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html

0

OK, thanks for the links I've had a look at those. Following that and what you said about focus, I run a little experiment with my application. I launched it, then typed on my keyboard and, as we know the text typed appeared inside the text area, but nothing happened to the keys on the virtual keyboard. Then I clicked on one of the keys on the virtual keyboard with my mouse and started to type again on my actual keyboard. Lo and behold, now the keys on the virtual keyboard change colour on key press and change it back on key release ( although for some strange reasons if I type too quickly they remain green, it's as if they don't have enough time to change back to the default colour) but there is no text appearing inside the textArea. I think I begin to understand this focus problem. So, one solution, as you hinted, is key binding. Looks a bit daunting thought I have to admit. The other solution, and please correct me if I'm wrong, is to:
1)disable the textArea so that you can't type in;
2)on keyPressed, get the character typed and copy it onto the textArea (although I have to find a way to make sure that when you press the spacebar you actually get a space rather than "space" and the same with the back button)
2)on keyPress make sure that the focus is on the button in the virtual keyboard, the button that correspond to the button pressed on the actual keyboard (moving the focus though doesn't seem to be that easy because every object I call the isFocusable(true)on, the compiler issues an error, like
currentButton.isFocusable(true);
or
event.isFocusable(true);
or
KeyEvent.isFocusable(true);
)

Edited by Violet_82

0

I think you mean setFocusable, not isFocusable

Your proposed solution is almost OK except you missed the whole point about key pressed vs key typed for the char that you will display.

Trying to control the focus is hard, and usually fails becuase the user can change it at will. You can add the same key listener to every component in your window, and then not worry about which had the focus.

0

I think you're right, I meant setFocusable(true), apologies.
You're right, I'm leaving the keyTyped out of the equation. Not that I don't think it's a good way to do it of course, I mean, I know for a fact that you're 100% right when you suggested that, but having seen that there is a perhaps (at least in my eyes of beginner) simpler way to sort things out I thought I'd try and it seems like that keyTyped isn't essential to get the character printed on the textArea. I understood what you said about it though and I do understand now the difference between the three types of events, it just seems to me that not all of them need to be used to achieve what I'm trying to achieve.
I had a go at it, and I think I sorted it, in a way that I seem to have got rid of the focus problem, pretty much the way I said I would in the previous post (set the textArea to uneditable, copy the character typed onto the textArea and I didn't even need to add the focus anywhere, things just seem to work). I then used a switch statement to work out what was pressed and act accordingly (if it's a space bar add a space, if it's any other button just do nothing except highlighting the corresponding virtual key button). Here is the relevant code:

import java.awt.Color;
public class TouchType extends JFrame{  
    private Color originalColour;//to get the background of the original colour before changing it
    private int theChar;//to hold the vk constant
    private JButton buttonToHighlight;//button to hightlight

    ...
    public TouchType(){//constructor
        ...
        super("Typing application");
        textArea.setEnabled(false);//disable textarea
        textArea.setDisabledTextColor(Color.BLACK);
        KeyHandler handler = new KeyHandler();
        for(JButton currentButton:mp.values()){//going through all the buttons
            currentButton.addKeyListener(handler);//add listeners to buttons
            originalColour = currentButton.getBackground();//get the original colour of the button, don't need to do that here, just for testing
        }       
    }//end of constructor
    //private class for event handling
    private class KeyHandler implements KeyListener{
        public void keyPressed(KeyEvent event){
            theChar = event.getKeyCode();           
            switch(theChar){
                case VK_SPACE:
                    character += " ";
                    break;
                case VK_BACK_SPACE:
                case VK_TAB:
                case VK_CAPS_LOCK:
                case VK_ENTER:
                case VK_SHIFT:
                case VK_UP:
                case VK_LEFT:
                case VK_DOWN:
                case VK_RIGHT:
                    character += "";
                    break;
                default:
                    character += String.format("%s", KeyEvent.getKeyText(event.getKeyCode()));//get the constant
            }           
            buttonToHighlight = mp.get(theChar);            
            buttonToHighlight.setBackground(Color.GREEN);           
            textArea.setText(character);
        }
        public void keyReleased(KeyEvent event){
            buttonToHighlight.setBackground(originalColour);
        }
        public void keyTyped(KeyEvent event){

        }
    }
}

All in all, I think I'm happy with the functionality, as it it a simple, with a reduced keyboard application, so maybe I shouldn't be covering all the possible alternatives. Three things though bother me:
1)because it is a reduced keyboard if I click a button that's not on the map I can se quite a few exceptions generated on the console: should I fix this do you reckon?
2)I need to sort out the size and button arragement on the GUI, and get it to look like a bit more like a keyboard layout. At the beginning of the thread you showed me a way to potentially change the width, is that still valid even if things have changed quite a bit since then? Also in terms of positioning the buttons, for example the up,left,down and right arrows, to achieve a standar keyboard positioning, is it worth adding some empty elements or is it easier to play on the padding?
3)it's something I mentioned earlier on, and it's still there unfortunately, may be standard behaviour I don't know, but if I type too quickly some of the buttons pressed remain green on the virtual keyboard, as if resetting the background colour didn't execute. Is that expected behavious if you type too quickly?
thanks

0

That code won't handle modifier keys (shift etc) correctly, and there's no quick fix for that. The only sensible way to get the correct character displayed is to use the KEY-TYPED event. It's also trivially easy. Forget the switch etc.

There are no guarantees about the order in which events will be delivered, so if you press/relase 2 keys quickly you MAY get
key1 pressed
key2 pressed
key1 released
key2 released
... in which case your existing code will lose track of which button. You need to use the VK in the key released event to know which key to un-highlight.

0

OK no problem, will use the keyTyped then.
Let's see if this is correct. KeyPressed will only get the constant of the button pressed on the actual keyboard, find the button in the map and change the color:

public void keyPressed(KeyEvent event){
            theChar = event.getKeyCode();           
            buttonToHighlight = mp.get(theChar);        
            buttonToHighlight.setBackground(Color.GREEN);
        }

keyTyped will work out which key it is and get it displayed on the textArea. I had a look at this keyTyped method and it seems that it only gets called if the key pressed isn't an action key, so I don't need to worry about those. Still i seems like I still need the switch statement to filter through space, enter and backspace keys, so make sure that the text "Enter", "Space" and "backspace" aren't added to the textArea. That's at least what happened when I removed the switch statement. I've also noticed that characters like "[", "]", ";", "/" print respectively "bracketClose", "bracketOpen", "comma", "semicolon", "slash". Does it mean that I have to add these cases in the switch too?

public void keyTyped(KeyEvent event){
            //String temp = KeyEvent.getModifiersText(event.getModifiers)
            switch(theChar){
                case VK_SPACE:
                    character += " ";
                    break;
                case VK_BACK_SPACE:             
                case VK_ENTER:              
                    character += "";
                    break;
                default:
                    character += String.format("%s", KeyEvent.getKeyText(theChar));//get the constant
            }
            textArea.setText(character);
        }

Method keyReleased finally.

You need to use the VK in the key released event to know which key to un-highlight.

I understand the scenario you provided and how we may not know which button needs to have its background colour set back to default, but the vk constant for the clicked button is already stored in the theChar variable, so should I create a temp variable, get the vk constant again find that particular button and set its background back to default? Or have I misunderstood? So something like this:

public void keyReleased(KeyEvent event){
            int theCharTemp = event.getKeyCode();
            JButton JButtonTemp = mp.get(theCharTemp);
            JButtonTemp.setBackground(originalColour);
        }

that seems to resove the issue...

Edited by Violet_82

0

Key released - the value in your theChar is useless if you get a sequence like the one in my last post. The code at the end of your post is the way to do it.

Your keyTyped is still far too complicated. Just get the Unicode char (NOT the VK constant) event.getKeyChar() and add it to the text area. That's all. One line of code. I guess you didn't read my previous posts too closely (sigh).

Edited by JamesCherrill

0

That works perfectly, and yes with just one line of code as you said, brilliant! I did read your post carefully :-), I think I simply didn't understand, my apologies, I didn't realize that by

The only sensible way to get the correct character displayed is to use the KEY-TYPED event

you meant to get the unicode value, my bad.
About the layout, I have done a bit of reading here and there, especially when it comes to size of the components etc. I've come across a Dimension and an Insets classes. I used the insets to give some padding to the textArea, which worked really well:
textArea.setMargin(new Insets(15,5,15,5));//sets margins inside the element
and then attempted to modify the size of the buttons with setMinimumSize() (I first tried to change them all, just to see if that works, and if that worked, then I'd target each button as needed, but alas it got me nowhere, nothing changed at all - I tried also setMaxSize but no joy:)

for(JButton currentButton:mp.values()){
            currentButton.addKeyListener(handler);
            originalColour = currentButton.getBackground();
            Dimension minimumSize = new Dimension(100,100);
            currentButton.setMinimumSize( minimumSize );

There seems to be a lot of discussions online about changing size of components by changing the layout manager, which, ideally, I wouldn't want to do.
Finally I came across a method called setPreferredSize(), on a post on stackoverflow. That seems to be doing something, as in when I use it the size of the buttons does change, so I think I'll play with that a little and see how it goes, do you think it is a reasonable option?
thanks

0

Insets work well, but the whole set minimum/maximum/preferred size, along with setSize itself is a nightmare. Different layout managers respect or ignore any or all of those depending on the phase of the moon or the presence/absence of a black cat in the room. Trial and error seems the only way.
Personally I just use GridBagLayout which is tedious but respects the settings you give it.

Edited by JamesCherrill

0

Understood, thanks. I may or may not redo this in GridBagLayout, not sure, will see if I have time to do that or move on with something else.
In any case, thanks ever so much for all your help and advices with this and for your patience, I've learned a lot by doing this exercise.

0

Here is the source code. Other beginners might find this useful, who knows.

 /*TouchType.java*/
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Dimension;//for setting the dimensions of a component
//import javax.swing.BorderFactory;//to set the borders
import java.awt.Insets;
//import java.awt.FlowLayout;
import javax.swing.JLabel;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.*;//needed for the key constants
import javax.swing.JScrollPane;
//for the map
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.TreeSet;   
public class TouchType extends JFrame{
    //private JPanel mainPanel;//wrapping panel
    private String character;
    private int theChar;
    private JButton buttonToHighlight;//button to hightlight when the corresponding one is clicked
    private JPanel labelPanel;//panel for labels
    private JLabel label1;//first label
    private JLabel label2;//second label
    private JPanel keysPanel;//holding the keys
    private JButton newButton;
    //rows panels for keys. 5 rows.
    private JPanel row1;
    private JPanel row2;
    private JPanel row3;
    private JPanel row4;
    private JPanel row5;
    private JTextArea textArea;//text area
    private BorderLayout bLayout1;
    private BorderLayout bLayout2;
    private GridLayout keysPanelLayout;
    private GridLayout gridLayoutRow1;
    private GridLayout gridLayoutRow2;
    private GridLayout gridLayoutRow3;
    private GridLayout gridLayoutRow4;
    private GridLayout gridLayoutRow5;
    private Color originalColour;


    Map<Integer,JButton> mp = new HashMap<Integer,JButton>();//declaring a map object 

    public TouchType(){//constructor
        super("Typing application");    

        //creating JPanels
        labelPanel = new JPanel(); //panel for labels
        character = " ";
        keysPanel = new JPanel();//panel wrapper for key rows
        row1 = new JPanel();//panel for row1
        row2 = new JPanel();//panel for row2
        row3 = new JPanel();//panel for row3
        row4 = new JPanel();//panel for row4
        row5 = new JPanel();//panel for row5

        //creating a button and adding it to the appropriate JPanel
        row1.add(createButton(VK_DEAD_TILDE, "~"));     
        row1.add(createButton(VK_1, "1"));      
        row1.add(createButton(VK_2, "2"));
        row1.add(createButton(VK_3, "3"));      
        row1.add(createButton(VK_4, "4"));      
        row1.add(createButton(VK_5, "5"));
        row1.add(createButton(VK_6, "6"));
        row1.add(createButton(VK_7, "7"));      
        row1.add(createButton(VK_8, "8"));      
        row1.add(createButton(VK_9, "9"));      
        row1.add(createButton(VK_MINUS, "-"));      
        row1.add(createButton(VK_PLUS, "+"));       
        row1.add(createButton(VK_BACK_SPACE, "Backspace"));
        row2.add(createButton(VK_TAB, "Tab"));      
        row2.add(createButton(VK_Q, "q"));      
        row2.add(createButton(VK_W, "w"));
        row2.add(createButton(VK_E, "e"));      
        row2.add(createButton(VK_R, "r"));      
        row2.add(createButton(VK_T, "t"));      
        row2.add(createButton(VK_Y, "y"));      
        row2.add(createButton(VK_U, "u"));      
        row2.add(createButton(VK_I, "i"));      
        row2.add(createButton(VK_O, "o"));
        row2.add(createButton(VK_P, "p"));      
        row2.add(createButton(VK_OPEN_BRACKET, "["));       
        row2.add(createButton(VK_CLOSE_BRACKET, "]"));      
        row2.add(createButton(VK_BACK_SLASH, "\\"));        
        row3.add(createButton(VK_CAPS_LOCK, "Caps"));
        row3.add(createButton(VK_A, "a"));      
        row3.add(createButton(VK_S, "s"));      
        row3.add(createButton(VK_D, "d"));      
        row3.add(createButton(VK_F, "f"));      
        row3.add(createButton(VK_G, "g"));      
        row3.add(createButton(VK_H, "h"));      
        row3.add(createButton(VK_J, "j"));      
        row3.add(createButton(VK_K, "k"));      
        row3.add(createButton(VK_L, "l"));      
        row3.add(createButton(VK_SEMICOLON, ";"));      
        row3.add(createButton(VK_EQUALS, "="));     
        row3.add(createButton(VK_ENTER, "Enter"));      
        row4.add(createButton(VK_SHIFT, "Shift"));      
        row4.add(createButton(VK_Z, "z"));      
        row4.add(createButton(VK_X, "x"));      
        row4.add(createButton(VK_C, "c"));      
        row4.add(createButton(VK_V, "v"));      
        row4.add(createButton(VK_B, "b"));      
        row4.add(createButton(VK_N, "n"));      
        row4.add(createButton(VK_M, "m"));      
        row4.add(createButton(VK_COMMA, ","));      
        row4.add(createButton(VK_PERIOD, "."));     
        row4.add(createButton(VK_SLASH, "/"));      
        row4.add(createButton(VK_UP, "up"));        
        row5.add(createButton(VK_SPACE, ""));       
        row5.add(createButton(VK_LEFT, "Left"));        
        row5.add(createButton(VK_DOWN, "Bottom"));      
        row5.add(createButton(VK_RIGHT, "Right"));  

        //SORT OUT THE LAYOUTS
        //border layouts
        bLayout1 = new BorderLayout();//for JFrame
        bLayout2 = new BorderLayout();//for labelPanel
        keysPanelLayout = new GridLayout(5,1,5,5);//for keysPanel, adds gaps between components, so rows
        //creating gridLayout objects for rows
        gridLayoutRow1 = new GridLayout(1,14,5,5);//row, cols, hgap,vgap
        gridLayoutRow2 = new GridLayout(1,14,5,5);//add gaps between components, so buttons
        gridLayoutRow3 = new GridLayout(1,13,5,5);
        gridLayoutRow4 = new GridLayout(1,12,5,5);
        gridLayoutRow5 = new GridLayout(1,4,5,5);
        //creeating elements
        textArea = new JTextArea(10,15);
        label1 = new JLabel("Type some text using your keyboard. The keys you press will be highlighted and the text will be displayed");
        label2 = new JLabel("Note: clicking the button with your mouse will not perform any action");

        //set layouts
        setLayout(bLayout1);//set layout of JFrame
        keysPanel.setLayout(keysPanelLayout);//set layout of keysPanel
        labelPanel.setLayout(bLayout2);//layout of labelPanel
        row1.setLayout(gridLayoutRow1);//set layout of row1
        row2.setLayout(gridLayoutRow2);//set layout of row2
        row3.setLayout(gridLayoutRow3);//set layout of row3
        row4.setLayout(gridLayoutRow4);//set layout of row4
        row5.setLayout(gridLayoutRow5);//set layout of row5

        //add elements to their panels
        labelPanel.add(label1, BorderLayout.NORTH);//add label to labelPanel, top
        labelPanel.add(label2, BorderLayout.CENTER);//add label to labelPanel, middle

        keysPanel.add(row1);//add row to keysPanel
        keysPanel.add(row2);//add row to keysPanel
        keysPanel.add(row3);//add row to keysPanel
        keysPanel.add(row4);//add row to keysPanel
        keysPanel.add(row5);//add row to keysPanel
        add(labelPanel, BorderLayout.NORTH);//add labelPanel to JFrame, top
        add(new JScrollPane(textArea), BorderLayout.CENTER);//add textArea to the JFrame, middle        
        add(keysPanel, BorderLayout.SOUTH);//add the keysPanel wrapper to the JFrame, bottom
        textArea.setEnabled(false);//disable textarea
        textArea.setDisabledTextColor(Color.BLACK);
        textArea.setMargin(new Insets(15,5,15,5));//sets margins inside the element

        /* for (Map.Entry<Integer, JButton> entry : mp.entrySet())
        {
            //System.out.println("value is " + entry.getValue());
        } */

        Dimension backButtonSize = new Dimension(100,50);
        JButton backspaceBtn = mp.get(VK_BACK_SPACE);
        backspaceBtn.setPreferredSize( backButtonSize );

        KeyHandler handler = new KeyHandler();
        for(JButton currentButton:mp.values()){
            currentButton.addKeyListener(handler);
            originalColour = currentButton.getBackground();         
            //this works
            /* Dimension preferredSize = new Dimension(100,100);
            currentButton.setPreferredSize( preferredSize ); */
        }


    }//end of constructor

    //private class for event handling
    private class KeyHandler implements KeyListener{
        public void keyPressed(KeyEvent event){
            theChar = event.getKeyCode();

            //character += String.format("%s", KeyEvent.getKeyText(event.getKeyCode()));//get the constant

            /* switch(theChar){
                case VK_SPACE:
                    character += " ";
                    break;
                case VK_BACK_SPACE:
                case VK_TAB:
                case VK_CAPS_LOCK:
                case VK_ENTER:
                case VK_SHIFT:
                case VK_UP:
                case VK_LEFT:
                case VK_DOWN:
                case VK_RIGHT:
                    character += "";
                    break;
                default:
                    character += String.format("%s", KeyEvent.getKeyText(event.getKeyCode()));//get the constant
            } */

            //character = String.format("%s", (event.getKeyCode()));//get the constant
            //KeyEvent.isFocusable(true);

            buttonToHighlight = mp.get(theChar);

            buttonToHighlight.setBackground(Color.GREEN);

            /* JButton buttonSizeTochange = mp.get(VK_BACK_SPACE);
            buttonSizeTochange.setMinimumSize(new Dimension(100,100) ); */

            //textArea.setText(character);
        }
        public void keyReleased(KeyEvent event){
            //buttonToHighlight = mp.get(theChar);
            int theCharTemp = event.getKeyCode();
            JButton JButtonTemp = mp.get(theCharTemp);
            JButtonTemp.setBackground(originalColour);
        }
        public void keyTyped(KeyEvent event){
            character += String.format("%s", event.getKeyChar());
            //String temp = KeyEvent.getModifiersText(event.getModifiers)
            /* switch(theChar){
                case VK_SPACE:
                    character += " ";
                    break;
                case VK_BACK_SPACE:             
                case VK_ENTER:              
                    character += "";
                    break;
                default:
                    character += String.format("%s", KeyEvent.getKeyText(theChar));//get the constant
            } */
            textArea.setText(character);
        }
    }

    //creates a button and adds it to the Map
    private JButton createButton(int keyCode, String name){
        newButton = new JButton(name);
        mp.put(keyCode, newButton);
        return newButton;
    }
}//end of TouchType class




/*TouchTypeTest.java*/
import javax.swing.JFrame;
public class TouchTypeTest{
    public static void main(String[] args){
        TouchType touchType = new TouchType();
        touchType.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        touchType.setSize(800, 600);
        touchType.pack();
        touchType.setVisible(true);

    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.