answersLogoWhite

0

How do you deal with right click in Java Swing?

Updated: 11/2/2022
User Avatar

Anubrata

Lvl 1
16y ago

Best Answer

You would implement a MouseListener class like so:

public class MyMouseListener extends MouseAdapter {

public class MyMouseListener() {}

public void mouseClicked(MouseEvent e) {

if (e..getButton() MouseEvent.BUTTON3) {

; //the third button (right?)

}

}

}

Then you add in what you want to do when the correct button gets clicked. After that, you create a MyMouseListener object and register it as a MouseListener for whichever component you are trying detect events for (e.g. a pop-up menu for a JFrame).

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you deal with right click in Java Swing?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is syntax errors in java?

Runtime errors in Java means that there is some code error existing in your computer and it is impossible for you to deal with it by yourself unless you are the you're the applet's designer and change the code. Most of the time, runtime errors in Java will appear error message just like: "Java(TM) Plug-in Fatal Error Several Java Virtual Machines running in the same process caused an error." "Java(TM)Plug-in Fatal ERror the Java Runtime Environment cannot be loaded."


The programming language C is an enhanced version of the programming language C?

Yes, the C++ programming language is an enhanced version of the C programming language.Of note: to increment a variable by 1 in C, you could type myInt++ (i.e. for(int i = 0; i < 1; i++). C++ was named C++ because it is one step above C (C + 1).


How do you deal with installing Java Access Bridge?

So, I followed every instruction in oracle, yet when I try to install a program(which needs access bridge) it gives me this error: java.awt.AWTError: Assistive Technology not found: com.sun.java.accessibility.AccessBridge I did absolutely EVERYTHING in the oracle site about 5 times. Still won't work. Anyone can help?


What is the difference between C and java?

You're comparing apples and oranges. C is a procedural language. You can, using structures and functions to access those structures do everything you can in Java. In fact, if you look into GObject, the object oriented method of programming in GTK (the Linux toolkit) people do this all the time. In fact they have pretty much implemented C++ manually using a programming style and macros. C++ and Java have a great deal more in common. From a language perspective, they are nearly identical. Java is arguably cleaner as it doesn't depend on forward declaration and therefore all functions are coded directly within the class definitions themselves. C++ is arguably more powerful as you have direct access to the hardware of the system and it's also possible to write code in such a way that it is guaranteed to be compiled an optimized in a specific manor. For application development, Java is often faster (performance and in the time it takes to get the job done). For system level development, C++ is almost always a clear winner. I won't detail it as it's far beyond the scope of the question. There are two key differences between Java and C++ to a programmer. 1) Java is a garbage collected language This means you can allocate memory and just forget about it when you're done. Some people say this leads to ugly code and quite frankly, I agree. Bad programmers can be REALLY bad programmers in Java and get away with it. C++ a C++ program will tend to crash your machine if you write it badly. The selling point of garbage collection is performance. It allows the runtime system of the language to clean up when there's time to do it instead of having to clean up during time critical moments. In C++ this type of behavior has to be coded manually and requires a great deal of strategic planning to accomplish. 2) Java has a "good" defined set of standard class libraries. C++ has libraries also, but only a small percentage of programmers use them because many of us (me included) consider them to be a plague on the language. They're VERY over-engineered and can be very hard to debug. Java's libraries are a lot cleaner even if they have serious inconsistencies (this may spur a political debate, but I offer my opinion and the arguments I've heard from others). Neither language is particularly good. Neither runtime is particularly modern. There are newer technologies such as C#/.NET and others which have arguably learn from C++ and Java and built upon what was learned. If you're learning to program, I recommend using C++ with Qt (from Nokia) as it gives you almost the best of both worlds. If you're using one and looking to switch to the other. It should be a smooth transition, the languages are basically the same. If you're asking about internal data structure. The two languages aren't comparable as Java doesn't have a strict internal structure definition and therefore can't be compared. P.S. - For a bonus, Java's best feature is relocatable memory. Because it forces you to never use memory locations directly (pointers), so the java virtual machine can relocate your memory in order to make room for larger allocations that otherwise wouldn't fit without paging or asking the OS for more RAM. This can make your applications more efficient as virtual memory paging is far more expensive than simply defragging the memory occasionally.


What is the big deal about green roof technology?

what is the big deal about gren roof technology

Related questions

What is spot deal?

highlighht what you want pasted, right click and click 'copy', then go into word and right click then click 'paste'. Or if you want the whole screen, press the 'PrtScn' button on your keyboard, then go into word, right click, and click 'paste'. :)


What is Java and are updates needed?

Java is a programming language.In IT sector there is a demand of change always so to overcome and deal with the demand there is a need of updating of java.


How did the Nazis deal with the swing youth?

Sent them to a concentration camp and killed them


Where can I find a deal on swing sets in Seattle, WA?

Toys 'R Us and Home Depot are two stores which often feature sales on swing sets.


How do you beat level 20 on the impossible quiz deal or no deal?

spam click 'No seal'


Where can i find the best deal on wooden swing sets?

For the best deal, try searching eBay.com and Craigslist.com. If you don't mind a used swing set, you can usually find one for free or very cheap on Craiglist, but you usually must pick it up yourself. On eBay, you may find a cheaper deal, but keep in mind you must pay shipping, which can be hundreds of dollars.


Where can I find the best deal on a Little Tikes swing?

Hi there, if you go to a website called pricerunner.com it will give you the best price on any item and tell you where to buy from, including your little tikes swing! Good luck


How do you deal with cyber bullying?

click on the 'report abuse' button if there one.


How do you get kits on girlsensecom?

1.) Log in 2.) go to My Boutique and then click on My Studio 3.) A tab with all the fashions you can make will show up, on the right side will be a box called "Daily Deal" also known as a kit. They do cost gcents, but not many. 4.) Click on "Get it"


How to be a lmader at roblox?

This refers to users in the who post on the Let's Make a Deal forum on roblox.com; click Forum on your header, then click the second choice: Let's Make a Deal. You must have super-safe privacy disabled.


How do you deal with your horemones if your only 13?

First you need to except them. Because for me after I excepted them they really become fun. At least the mood swing part:D


Can you deal cards to your right in euchre?

No, in euchre, and in almost all card games, you deal to your left.