• 0

JAVA GUI error message


Question

package Lab4;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class GUI_Element implements ActionListener{
    // Create a frame window

    public static final int WIDTH = 500;
    public static final int HEIGHT = 400;
    public static final int NUMBER_OF_DIGITS = 30;

    private JTextField ioField;
    private double result = 0.0;

    public GUI_Element () {
        JFrame frame = new JFrame ("Mortgage Calculator");
        frame.setSize (WIDTH, HEIGHT);
        frame.setLayout(new GridLayout(7,1,10,10));
}

Okay so I have this java program written. i'm trying to build a GUI for the first time, so just a beginner at this and I'm using Netbeans.

I get this error on the class name GUI_Element

GUI_Element is not abstract and does not override abstract method actionPerformed in java.awt.event.ActionListener

I have no idea why I'm getting this error.

Please help

Link to comment
https://www.neowin.net/forum/topic/886128-java-gui-error-message/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

I dont mess with gui at all but it could be that you need super() in your constructor as the class is implementing the awt.

^ thats not it.

you could just make the class abstract and implement everything that is needed in your constructor.

public abstract class GUI_Element implements ActionListener{

  • 0

Your class GUI_Element implements an interface (ActionListener). ActionListener requires that implementing classes override the method actionPerformed. You need to define a method called actionPerformed.

It must match the signature in http://java.sun.com/javase/6/docs/api/java/awt/event/ActionListener.html .

so something like:

public void actionPerfomed(ActionEvent e){
   if(e.getSource()==jButton1){
      //do work
   }
}

  • 0

Okay so after adding more code to my file, this is what I ended up with. It looks right to me but the only thing that I need is to make the text field, button smaller so that I can fit the outputs on the same window. I have in all 7 outputs. In the picture I've only shown 2 for now.

Is there a way to make the textfield and button smaller?

Thanks.

post-234729-12694907304266.jpg

  • 0

A GridLayout will make every Component in the Grid the same size no matter what. GridBagLayout will let you set relative sizes, but it's somewhat difficult to figure out. The best bet if you don't want to code the GUI by hand is to use NetBeans IDE. It has a drag-and-drop GUI creator.

Otherwise, you'll want to read this: http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

  • 0

^ Thanks for the link. I tried using BorderLayout in mine.

Seems okay to me till now.

Now where I'm stuck is, I want the text "Status of the Program: Waiting for user to enter all the values" to fit on the window. However, my GUI cuts it off. I have no idea how to make it not cut the text I've written.

Any help please?

Thanks :)

post-234729-12695709436469.jpg

  • 0

I don't quite understand how we use HTML tags. Can you give me a link that will make things more clearer?

I'm building on Netbeans. I have an assignment and its due tomorrow :(. I can't use the Netbeans GUI builder. I have to write all the code myself.

Thanks for the help :)

EDIT:

nvm I found this link:

http://java.sun.com/docs/books/tutorial/uiswing/components/html.html

Thanks for the kind help dontocsata!

EDIT2:

okay still stuck. So I have this:

        status.setText(" <html><b>Status of the Program: Waiting for user </b> <b>to enter all the values</b>");

where status is a JLabel.

HTML doesn't seem to work in this.

I don't really know if I'm right though.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • "Asus points out the security aspect, that you will lose support and thus there will be no security updates leaving your system exposed" Both Microsoft (for 3 years) and 0patch (for 5 years) offer ongoing security patches for a fee. https://learn.microsoft.com/en...w/extended-security-updates https://blog.0patch.com/2024/0...windows-10-with-0patch.html
    • I won't switch to W11 at home until I absolutely have to. This deadline depends on how long third-party software will be supported on W10 (such as browsers and image viewers and so on). I estimate that migration will be necessary around 2028, when the ESU program expires, but we'll see.
    • "not so intelligent after all" may be the best summary of this whole mess. And yeah, those opt-outs are practically hidden like Easter eggs, if you're lucky enough to even find them.
    • Asus joins Microsoft, AMD, Dell, urges you to "prepare for mandatory Windows 11 upgrade" by Sayan Sen Sometime earlier this year, Microsoft quietly updated the minimum CPU requirements guidance for Windows 11 24H2. Neowin noticed the change this past week as the support document now classifies a family of CPUs from each vendor, AMD, Intel, and Qualcomm, such that users find it easier to make out which processors are capable of being Copilot+ PC certified. Major OEM and hardware manufacturer Asus recently published a couple of blog posts regarding the upcoming Windows 10 end of support. The company says that it is now time to "prepare for the mandatory Windows 11 upgrade" by taking "essential steps." It writes: "With a mandatory Windows update on the horizon, there are essential steps you should take to ensure a smooth upgrade experience. Proper preparation will not only safeguard your files and system but will also allow you to take full advantage of the innovative features Windows 11 has to offer..." If you are on Windows 10 and are wondering why should you even bother upgrading, Asus points out the security aspect, that you will lose support and thus there will be no security updates, leaving your system exposed. The firm is certainly right, there are real dangers out there. For example, the Lumma infostealer impacted over 394,000 PCs worldwide (download this Defender definition for new ISO installations). Even official Windows files and folders can be vulnerable as we saw with the inetpub folder. However, Asus wants you to get excited about Copilot, the new AI assistant that Microsoft has been busy pushing everywhere on its apps and services. Echoing the same sentiment as Microsoft, and others like Dell and AMD, Asus says Copilot is what sets Windows 11 apart from 10 as it writes: "What makes Windows 11 different? One word: Copilot. ... If you’ve ever wished your computer could just “do the thing” you’re trying to describe — Copilot is your new best friend." Asus also says that you will be making the "smart move" by switching to Windows 11 now from 10. In the blog post under a subheading titled "It’s Not Just an Upgrade, It’s a Smart Move." The Taiwanese firm writes, "Upgrading to Windows 11 isn’t just about staying current ― it’s also about staying safe, working smarter, and getting more out of your computer every day." As such, the company also published a guide on how to proceed with the upgrade. Do you agree with Asus? When are you upgrading? Let us know below!
  • Recent Achievements

    • Posting Machine
      Fiza Ali earned a badge
      Posting Machine
    • One Year In
      WaynesWorld earned a badge
      One Year In
    • First Post
      chriskinney317 earned a badge
      First Post
    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      181
    2. 2
      snowy owl
      130
    3. 3
      ATLien_0
      127
    4. 4
      Xenon
      119
    5. 5
      +Edouard
      91
  • Tell a friend

    Love Neowin? Tell a friend!