nomad 664
Recognized Expert Contributor
I need help with JcomboBox
When and User select the Exit in the File box it will the
//inner class
class exitListener implements ActionListener {
...
}
which it open a window asking them if they want to close the program.
I have a statement
filemenu.setMne monic(KeyEvent. VK_X);
But the setMnemonic(Key Event .VK_X) is wrong.
Also I want to be able to drag down and select Exit.
Can someone please help me on this.
Here is my code... - class MyFrame extends JFrame {
-
String[] file = { "New", "Open", "Exit" };//items for file
-
String[] edit = { "Cut", "Copy", "Paste" };//items for edit
-
JComboBox filemenu = new JComboBox();
-
JComboBox editmenu = new JComboBox();
-
-
-
public MyFrame(String title) {
-
super(title);
-
this.setSize(250, 250); //sets the size for the frame
-
this.setLocation(200, 200);//location where frame is at
-
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
// setup contents
-
makeComponents();
-
initComponents();
-
buildGUI();
-
-
// display
-
this.setVisible(true);
-
}
-
-
private void makeComponents() {
-
-
JPanel pane = new JPanel();
-
// file menu section
-
filemenu = new JComboBox();
-
JLabel fileLabel = new JLabel();
-
pane.add(fileLabel);
-
for (int i = 0; i < file.length; i++)
-
filemenu.addItem(file[i]);
-
pane.add(filemenu);
-
add(pane);
-
setVisible(true);
-
-
//edit menu section
-
editmenu = new JComboBox();
-
JLabel editLabel = new JLabel();
-
pane.add(editLabel);
-
for (int i = 0; i < edit.length; i++)
-
editmenu.addItem(edit[i]);
-
pane.add(editmenu);
-
add(pane);
-
setVisible(true);
-
}
-
-
private void initComponents() {
-
-
filemenu.addActionListener(new exitListener());
-
}
-
-
-
//inner class
-
class exitListener implements ActionListener {
-
public void actionPerformed(ActionEvent arg0) {
-
-
int x = JOptionPane.showOptionDialog(MyFrame.this, "Exit Program?",
-
"Exit Request", JOptionPane.YES_NO_OPTION,
-
JOptionPane.QUESTION_MESSAGE, null, null,
-
JOptionPane.NO_OPTION);
-
if (x == JOptionPane.YES_OPTION) {
-
MyFrame.this.dispose();
-
}
-
-
}
-
}
-
-
-
-
-
private void buildGUI() {
-
Container cont = this.getContentPane();// set gui components into the frame
-
this.setLayout(new FlowLayout(FlowLayout.LEFT));// Comp are added to the frame
-
cont.add(filemenu);
-
cont.add(editmenu);
-
}
-
-
// / inner classes
-
-
}
-
-
-
-
public class ButtonFrame {
-
-
public static void main(String[] args) {
-
-
MyFrame f1 = new MyFrame("This is my Project for GUI");
-
}
-
-
}
Thanks
nomad
1 1608 JosAH 11,448
Recognized Expert MVP
Your filemenu isn't a menu at all, it's a JCombobox. Have a look at the JMenu
and [b/JMenuItem[/b] classes; they make up the parts of your drop down menus.
Those classes implement the mnemonics methods and a bit more.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ste |
last post by:
Hello,
my goal would be implementing some keystroke analysis using php. I'm a
novice in php, so i ask your advice: according to you, is it possible
to log each keystroke client-side even if php is a server-side
language, or shall i use JavaScript and make the client run the
program locally? And, if i can use php to do that, how can i implement
a feature logging keystrokes on the client system?
Thanks,
|
by: hokieghal99 |
last post by:
Does anyone know of a keystroke logger that has been written in Python
for Windows machines? I'd like to see such a script and use it as a
point of reference for a real-time backup project that I'm working on.
Basically, I'd like to be able to capture all keystrokes from the
keyboard buffer and write them to a text file so I could reporduce
emails, documents, etc. in the event of file loss that occurs between
nightly backups. For example,...
|
by: Wayne Wengert |
last post by:
I want to get the decimal (integer) value of user keystrokes. I am using the
following code. chrInput is the character entered (e.g. "M") and "keystroke
is DIMed as Short
keystroke = Microsoft.VisualBasic.Val(chrInput)
but it always yields a value of 0
How should I be doing this?
|
by: Lucy |
last post by:
help! javascript inline of an HTML to open an HTML in a target window.
Something like...
<html>
<head>
<title>test</title>
</head>
<body>
|
by: Frank Bormann |
last post by:
Hi,
probably a stupid question, but I haven't been able to find anything.
Is there a istream related function that let me read exactly one keystroke
from the keyboard through cin?
What I need it to do is this:
- remove all characters currently in the input buffer
- block until the user presses a key
| |
by: BC |
last post by:
I have read the FAQ and the discussions but I am not a Javascript
programmer and do not know how to make toFixed (and other techniques)
work, after several attempts.
The following calculations work when the form is submitted (and maybe
they should not...), but I do not know how to add a Rounding function
to the existing code, so that each Result is Rounded to 2 decimal
places.
toFixed sounds like it would be ideal...
|
by: Martin Holm Pedersen |
last post by:
Hey All..
Im having a bit of a problem with my program that i wrote for linux in c. I
use select() to monitor if the user has pressed a key and reads the key
with read(). It works fine om my IBM laptop but once i move the program to
my dell laptop it seems like it doesn't even recognize the select-function.
That is, it doesn't use the timeout assigned at all. I don't get any errors
when i compile on either computer. I run debian/testing on...
|
by: Joseph Geretz |
last post by:
I'm noticing that when my DataGrid has focus, it handles the Enter key by
advancing to the next row in the grid. This neutralizes Forms's current
defined AcceptButton.
My primary question: is there any quick way to configure the Grid not to
handle the Enter key? I do not see any property control which might
configure this behavior.
My secondary question: If there's no quick solution via Grid configuration,
then how do I get the...
|
by: Cron |
last post by:
Hi can someone give me a hand with this please?
I'm trying to build a search filter that scans through a list of
client names in a database as you type into a text box and filters the
form records accordingly. The problem is my database structure is
making it difficult: I need the filter to first lookup the partially
inputted name in the clients table and then filter my invoices
according to the clientID from that table. Here's what I have...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |