473,659 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

public JMenu add(JMenu c)

-
there is a "public JMenu add(JMenu c)" method in JMenuBar.

i'm not good in programming and am wondering whether someone can provide
me with a clarification why Sun chooses to return a JMenu, rather than a
boolean or simply a void? returning a void won't be useful in
determining whether it is added hence that is understood.

in what scenario does returning the JMenu?
Jul 17 '05 #1
1 1834

"-" <no****@hoem.co m> wrote in message
news:42******** @news.starhub.n et.sg...
there is a "public JMenu add(JMenu c)" method in JMenuBar.

i'm not good in programming and am wondering whether someone can provide
me with a clarification why Sun chooses to return a JMenu, rather than a
boolean or simply a void? returning a void won't be useful in determining
whether it is added hence that is understood.

in what scenario does returning the JMenu?


It's just a design decision. Returning a boolean for success or failure
is more of a C/C++ style of programming. In Java, it's typically better to
throw an exception if a failure occured.

As for why not returning void, if I designed the JMenuBar class, I'd
probably make it void. Still, I could see how it might be useful to have it
return the JMenu just added. Compare the following too pieces of code:

JMenu theJMenuThatIWa ntToSave = createSomeJMenu Object();
someInstanceOfJ MenuBar.add(the JMenuThatIWantT oSave);

.... versus ...

JMenu theJMenuThatIWa ntToSave =
someInstanceOfJ MenuBar.add(cre ateSomeJMenuObj ect());

- Oliver
Aug 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2849
by: Alex Ostrikov | last post by:
Hello, all !!! I have JFrame with JTabbedPane and JMenu. Each tab of JTabbedPane has JApplet on it. And when I choose any menu item (File -> DoSmth), my JApplet covers the part of menu so that it' not visible. Looks like applet is above the menu and covers it's part. I cann't get what the problem.
0
1904
by: dawntildusk | last post by:
I am trying to get cut and paste to work from menu. Below is code I have can someone point me where I am going wrong I have the same problem with File selection to open and save using JFileChooser. import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable;
4
3633
by: cnixuser | last post by:
Hello, I am posting reguarding some modifications I made to a text editor program that I wrote in my java class at my school today. The file I was modifying is a very simple java text editor with a "JMenuBar" object, with "JMenu" objects, such as "File" with "JMenuItem" objects such as "Save". The Modifications that I am attempting to make to the program are designed to give actual functionality to the "JMenuItems", starting with the "Save"...
0
1016
by: sandyw | last post by:
Hello Everyone: I need some help with a GUI project. What I want to do is when someone select the File Menu and chose New a Jpanel will open. I have tried to write the code which is called class labelListener implements ActionListener. The Bold font is where I need help in... Here is the code I have so far public class GUIMenu extends JFrame { public GUIMenu() {
9
9822
by: aleplgr | last post by:
Hi! I'm trying to let the end-user select the language of the menues I'm showing him. To do that I've got this Selector class that shows the end user a combo box, a label and a button. In the combo box the user selects the language (English,Spanish,French,..) and when he clicks in the button shows the label in the language selected. This works fine but it's just one form, I need to change the language of all the menues in an application, so...
2
5660
by: thesti | last post by:
hi, is it possible for each of the JMenu in my app have an icon. or is there any workaround? thx
1
1329
by: nt5515 | last post by:
hey Im trying to make a game of pairs (the memory game) i have set up a grid which displays a graphic for the card back. im trying to link the edit menu to choose the graphic to be displayed. i've set up a string variable called deck which will contain the path to the required image. and actionlisteners DA and DB corresponding to which style is choosen in the menu. I had to declare the deck to some initial image so it can load. How do i...
6
1664
crystal2005
by: crystal2005 | last post by:
Hi there, I need some help to correct my code. I would like to create a menu bar with the implementation of OO. So, i think i can edit and change it easyly if i use some classes. package gui_layout_BM; import javax.swing.JFrame; public class layoutDriver { public static void main(String args) { JFrame frame = new JFrame("Bovinetine Maker Simulator");
5
2534
by: brendanmcdonagh | last post by:
Hi, I am accessing my jtable via sf1.setText((String)table.getValueAt(selectedRow, 1)); sf2.setText((String)table.getValueAt(selectedRow, 2)); sf3.setText((String)table.getValueAt(selectedRow, 3)); sf4.setText((String)table.getValueAt(selectedRow, 4)); sf5.setText((String)table.getValueAt(selectedRow, 5)); sf6.setText((String)table.getValueAt(selectedRow, 6));
0
8851
Oralloy
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...
1
8525
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,...
0
7356
agi2029
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...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.