Button problem, can't get the bubble to...
I can't get my button to delete the text in a text area.
My code:
package events;
import java.awt.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class Main extends JPanel
implements MouseListener {
JTextArea textArea;
static final String NEWLINE = System.getProperty("line.separator");
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
UIManager.put("swing.boldMetal", Boolean.FALSE);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
private static void createAndShowGUI() {
JFrame frame = new JFrame("MouseEventDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new Main();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
public Main() {
super(new GridLayout(0,1));
textArea = new JTextArea();
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(200, 75));
add(scrollPane);
Button button = new Button("Clear");
textArea.add(button);
button.setVisible(true);
button.setSize(100, 100);
button.setLocation(100, 100);
addMouseListener(this);
setPreferredSize(new Dimension(450, 450));
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
public void buttonClick(WindowEvent e){ //THIS is where i'm having trouble
textArea.setText("");
void eventOutput(String eventDescription, MouseEvent e) {
textArea.append(eventDescription + " detected on "
+ e.getComponent().getClass().getName()
+ "." + NEWLINE);
textArea.setCaretPosition(textArea.getDocument().getLength());
public void mousePressed(MouseEvent e) {
eventOutput("Mouse pressed (# of clicks: "
+ e.getClickCount() + ")", e);
public void mouseReleased(MouseEvent e) {
eventOutput("Mouse released (# of clicks: "
+ e.getClickCount() + ")", e);
public void mouseEntered(MouseEvent e) {
eventOutput("Mouse entered", e);
public void mouseExited(MouseEvent e) {
eventOutput("Mouse exited", e);
public void mouseClicked(MouseEvent e) {
eventOutput("Mouse clicked (# of clicks: "
+ e.getClickCount() + ")", e);
I'm having trouble HERE
public void buttonClick(WindowEvent e){
textArea.setText("");
The button is declared here
Button button = new Button("Clear"); //Name
textArea.add(button); //Adding the button to text area
button.setVisible(true); //Needs to be visible
button.setSize(100, 100); //Square
button.setLocation(100, 100); //Middle of TextArea-----------------------------------------------------------
All help appreciated!!
yawmark wrote:
Isn't that declaring the function for the button? Not really. You'll need to have an object listen for button events.
[http://java.sun.com/docs/books/tutorial/uiswing/events/]
Also:
1. Don't mix AWT components with Swing components.
2. Please post Swing questions in the Swing forums.
~I agree with yawmark on this. It even states in the API that Swing and AWT components should NEVER be used together. Swing is JVM generated, so it will not work with the OS generated AWT well.
Similar Messages
-
KM4M Problem ( can't get the usb to work anymore).
Hi there people.
My mainboard apparently no longer recognises the USB ports as well as the ethernet one. I am not sure what the problem is, has anyone else experienced this? I had stopped using the PC in December but recently tried to connect it to my peer-to-peer network and found this out.
Cheers.Moan Guide
If you are having problems with USB ports, read this topic. -
How can I get the screen to lock on my iPhone 4, so I don't press buttons while talking?
I just upgraded to the iPhone 4. When I am talking on the phone, the screen doesn't lock, so I am constantly pressing buttons or hanging up on the person I'm talking to. How can I get the screen to lock while I'm talking? It's driving me NUTS.
The otterbox is one of the culprits. Take the phone out of the case and see if it still happens. If so it is not the case. If the problem goes away, then you may need to make the hole slightly larger. My family has three iPhone 4's in otterboxes and none have this problem. Other users on this forum have reported success with the above methods.
-
i have a macbook pro. i think i might have pushed some buttons that made my macbook look for a wireless keyboard.. i dont have any wireless keyboard. and now i cant use the keyboard on my macbook. how can i get the normal keyboard staring?
korgba wrote:
it pops up a script were it says that the macbook cannot find a bluetooth keyboard, and it isnt a keyboard connected
For some reason, your Mac doesn't recognise that a keyboard is present, so it looks for a wireless keyboard. The question is, why doesn't your Mac recognise that a keyboard is attached?
First, you need to make sure you remove all peripherals, especially USB peripherals (the keyboard is on the USB bus). Then restart holding down the Shift key. This should boot in Safe mode. If the computer boots normally (not in safe mode) and the keyboard is still not working, try resetting the SMC
Intel-based Macs: Resetting the System Management Controller (SMC)
<http://support.apple.com/kb/HT3964>
If that still doesn't fix the problem, then the keyboard (or its controller) is probably damaged and needs to be replaced. -
I have just updated to Yosemite, but now I can't get the custom short-keys to work.
In Mavericks I had no problem whatsoever, but now even after googeling and restart no solution.
Does anyone have the problem? All the other shortcuts work!Hi Thomas,
I can confirm the problem you are hitting. The XML test trace does not get recognized at all, and it defaults to Eclipse's basic Open File behaviour. I am not sure if it's because the format definition is missing, or if it's because something prevents the trace type from being recognized. I will open a bug about it.
Thanks for identifying this issue!
In the meantime, if you'd like to experiment with XML analyses, you can also take a look at the example at https://github.com/tracecompass/xml-analysis-example .
Cheers,
Alex -
How can I get the 23 July update to load onto my iPad. I haven't been able to access my documents or work for weeks and need to use it. Has anyone else had similar problems?
Hello Arthur,
Thank you for the reply.
You were correct that deleting the app and reinstalling it was the only thing to make it work but unfortunately I lost all the documents I made, even though they were backed up to iCloud before i deleted the app. At the same time as deleting pages I had to delete keynote and numbers too, so I've lost all the documents in them too.
The mb of data which was assigned to each programme in iCloud has reduced, so. I guess they are gone for good. Is there any other way to reaccess them?
Not your fault but I am a bit fed up the the iPad. I have lost work that I've done and have no other copy apart from what was in iCloud, as I don't have a printer and couldn't email them too myself as I couldn't get into the programme and i've also got episodes of tv series I purchased that I can't download and albums that are half downloaded with songs missing, so I feel a bit swindled out of time and money and am going back to DVD , pen and paper and CDs .
Instead of using iCloud I guess the only way to make sure I don't loose any more documents it to email them to myself each time I save them on the iPad. Is there anything else you could suggest please?
I don't have any other apple products apart from iPods, so I can't access the iCloud on anything else can I?
Thanks
Amanda -
Hi I use CA Internet Security Suite which checks ALL pages and searches, but it does not work with this version, also I wish to use Goggle Toolbar which ALSO does not work with this version where can I get the previous version? As my harddrive crashed I have had to install windows 7 and this version doesn't seem to allow me to change my homepage, why is this? Cheers Ernest
You can get the latest version of Firefox 3.6 from http://www.mozilla.com/en-US/firefox/all-older.html
Mozilla are working to prevent Mac users with non-compatible systems from getting the notification about Firefox 4, and also not displaying the "Download Firefox 4" button on http://www.mozilla.com -
Firstly, I can't open iPhoto on my macbook as of a few days and could it have anything to do with a problem I have updating my iPhone's software as I've downloaded extra iCloud storage but I still can't get the iPhone to recognise the space for software
No. With the amount of information you've provided it's impossible to offer a potential solution. We can't see your computer so we need to know the details of your problem and setup, i.e.:
what version of iPhoto are you using?
what system version are you running?
what do you see when iPhoto opens?
what fixes have you tried?
where is your library located?
did you apply any updates or upgrades just prior to the problem occurring?
are you running a "managed" or "referenced" library?
what type of Mac?
how much free space on your boot drive?
For the iPhone issue ask in the iPhone forum.
OT -
I read the information on the help pages,but I can t get the menu bar to appear using the advice given.
Right click the Home button.
-
Ok so I have an iPod touch 4th gen and I purchased some music on it. I also have an iPad mini and wanted to download it onto there also. Problem is that no matter how many times I try I can't get my purchased music section to load. I get the big at the top where you can select all or not on this iPad and the alphabet down the left hand side and the little loading thingy appears but nothing ever actually loads no matter how long I wait. It also sometimes just crashes the whole thing and kicks me out the app. Any suggestions? I've tried turning device on and off, it has the latest software iOS 7 and I've tried resetting all the settings already also as well as logging in and out of my Apple ID.
Hello AstarteLydianna,
The following article provides some additional troubleshooting steps that can help get the App Store working on your iPod Touch.
Can't connect to the iTunes Store
http://support.apple.com/kb/TS1368
Cheers,
Allen -
help, are you having the same problem? iPad 2 calendar, can't get the month of March, can get days in March, but not month view. Any suggestions, thank u.
Hi melbernai - not sure if you've solved this problem yet. I had the exact same problem recently with my 2nd Gen iPod Nano. I solved it yesterday by simply updating iTunes to the most recent version, after which I could get rid of the register screen. The only other thing I needed to do to add my custom playlists was select "Manually manage music" on the screen for my iPod, since it had been in an automatic synching mode since the problem occurred.
-
I downloaded a film from ITunes in HD and had problems, I upgraded to the latest version of ITunes and have then downloaded the film again in SD on my Windows 7 computer, but I still can't get the film to play, any idea's what to do next?
I've been working at the same problem for hours now and it's really driving me crazy so any help would be greatly appreciated.It is working now. I no longer get the message about the item not being available in the US and I can access the store.
-
I can't get the volume to work when I watch a you tube video, there's no volume slide under the play button and my volume control on my I pad don't do anything to help, but yet my volume works perfect on everything else, what can I do???
do u have your ipad doing airplay because that could happen
-
My Safari Icon ( Button) is missing on my iMac after I downloaded a update. How can I get the icon (Button Safari) back on my desktop and connecting again to the Internet ?...
Thanks for the helpOften when people think they've deleted an application, what's really happened is that they deleted its icon from the Dock. In the Finder, select
Go ▹ Applications
from the menu bar, or press the key combination shift-command-A to open the Applications folder. If the application is in that folder, drag it to the Dock (not to the Desktop or anywhere else.) The other Dock icons will move out of the way to make a place for it. -
I have Windows 7 and PS Elements 10 and can't get the text button to work properly. What can I do?
Try selecting the T tool and then doing a reset (see image below)
Maybe you are looking for
-
How to add osd file into app-v package - need to have two osd files within one app-v package
We have app-v 4.6 sp2 I get one app-v existing package which has two OSD files associated. It is needed for separate license servers located in different sites. I need to create a new app-v package with new version of this application and want to hav
-
Why is local video streaming to Apple TV jerky?
Video streaming to Apple TV (v 3) has always been smooth. No matter what the online source -- from YouTube to Netflix -- the video is consistently good. Video streamed from Macs, though, is jerky to the point of unwatchable. Even when I stream it fro
-
Monthly average at run time.
Hi, My report contains,say 10 ,records for each month.can I get an average of a keyfig in that month when I run my query? Kind regards, Aru
-
GTK in Sun Studio project (question)
I'm new to Sun Studio. My background is 22 years c/c++ non-unix development (embedded systems & Windows application development). I'm trying to write a GUI based c++ app for Solaris. I know this is a complete newbie question. Any help will be GREATLY
-
How Abstract class differ, When we call class to be Abstract data type?
We say as Classes as a realization of Abstract data types, then why should we declare that to be abstract ? Hope, the key word Abstract in both ADT and abstract classname mean the same.!!!!