I have a calculator application in java swing, which is working properly with mouse click input. Now I want it to read input using keyboard button stroke. I had heard about the glass pane in java tutorial, but i need to know any other simple method to meet the requirement.
KeyPadPanel is an example that uses Action and Key Bindings for numeric entry.
Related
I have been recently trying to figure out what I should use to get user input in a GUI. I want the user to input text into the GUI and have the program save the text so I can use it later. I already have a basic understanding of programming GUI's. Any help is much appreciated!
You can use JTextField or JOptionPane.showInputDialog. Is your question is how can you get the input value from this Swing? Or just asking what you can use?
I suggest you work your way through the Swing tutorial, specifically the section on text widgets.
I made a simple JFrame with Swing. I want to know how I would go about making a non-visible input that would open up another JFrame I have in another class. (Like cheat codes in video games, you enter a combination and something happens.) I am not sure how to capture the user input without a text field.
You should use keybinding attached to your JFrame. You would want to store keystrokes as a String internally and after each keystroke, see whether the user has entered a recognizable cheat code or just listen for a return keypress as a delimiter for the code.
Keep in mind that if a component within that JFrame has focus and also implements the same key bindings, then that component will take precedence over the JFrame, effectively intercepting the keystrokes.
I have a calculator application in java swing, which is working properly with mouse click input. Now I want it to read input using keyboard button stroke. I had heard about the glass pane in java tutorial, but i need to know any other simple method to meet the requirement.
KeyPadPanel is an example that uses Action and Key Bindings for numeric entry.
So my situation is simple (IMHO):
I am trying to create web-esque Java application (it's a sort of Point-Of-Sale application) that behaves much like a website, but is all in Java. Right now I have a semi-simple SWT application written in Eclipse and it displays a few options (sign in, price check, inventory check and employee timeclock). When any of these is pressed (or corresponding keyboard shortcuts are activated) a dialog box pops up prompting authentication. Assuming user is verified, I want the main application window to display a new set of functions (scan item, item lookup, etc.) seamlessly.
If this were HTML I would just make a new page, and if I were writing against the Android platform I would just create a new activity...but this is very new and I am having a very hard time finding any relevant information.
PS I'm not set on SWT if anybody thinks a different library/technology (such as Swing/AWT) is better.
In SWT, if you want to replace the content of a Composite, you first need to dispose the existing controls, next you create the new controls, and finally call the layout(...) method on the Composite:
// Retrieve existing composite
Composite composite = [retrieve existing composite]
// Remove exising children
for (Control child : composite.getChildren()) {
child.dispose();
}
// Create new children
Label label = new Label(composite, SWT.NONE);
// Layout
// Maybe update the composite layout with composite.setLayout()
composite.layout(true, true);
Another solution is to use a Composite with a StackLayout if you want to display back and forth several predefined contents.
Whether you use Swing, AWT or SWT is entirely your choice. Personally, I prefer Swing, but you can do the same thing with SWT.
As for your predicament, you need to do a bit of studying regarding GUI's first. A Java desktop application consists of a top-level container, usually a JFrame (Window) that can contain other components, windows, dialog boxes etc. Your best best here is to pop up a MODAL dialog box that asks the user for authentication information. If the user is authenticated, you can dynamically create buttons, text boxes etc. in your code, creating the "new" look you want.
Might I suggest you start of with some simple GUI design exercises first, before diving into a full-fledged application? Consider the Java GUI tutorials at http://docs.oracle.com/javase/tutorial/uiswing/ as a good starting point.
Once you have mastered basic dialogue boxes, forms and components, you'd be in a far better position to plan your GUI and will find it easier to create it just the way you want it.
I am creating a chat application using JApplet. I have a TextArea where all chat messages go. Everything in working fine and smooth just as you would expect a basic chat application to do. Now i want to add support for gestures. I wanted to know, how can we show an icon in TextArea? it only takes string in append() method.
You should probably be looking at JTextPane instead of JTextArea.
Have a look at this tutorial which among other things, gives this demo: