Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3979848
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:13+00:00 2026-05-20T05:13:13+00:00

I’m learning Java, and now that I’m over the packages hump, things are going

  • 0

I’m learning Java, and now that I’m over the packages hump, things are going smoothly. I can draw similarities between most things I’m learning with things I already know at least the concept of. But what on earth is going on with the following bit of code? Is it some form of constructor, or anonymous object?

Something obj = new Something()
{
  private static final int num = 3;

  public void meth()
  {
    // w/e
  }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:13:14+00:00Added an answer on May 20, 2026 at 5:13 am
    /**
     * Notice there's only one thing in this that isn't defined:
     * It still needs public abstract void triggerEvent();
     */
    public abstract static class TopButton extends JPanel implements MouseListener {
            protected ButtonPanel parent;
            private String text;
            public TopButton(ButtonPanel bp, String text) { parent = bp; this.text = text; addMouseListener(this); }
            public void mouseClicked(MouseEvent e) { triggerEvent(); }
            public void mouseEntered(MouseEvent e) { }
            public void mouseExited(MouseEvent e) { }
            public void mousePressed(MouseEvent e) { }
            public void mouseReleased(MouseEvent e) { }
            public abstract void triggerEvent();
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                Color oldColor = g.getColor();
                Font oldFont = g.getFont();
                    Font newFont = new Font(oldFont.getName(),oldFont.getStyle(),oldFont.getSize());
                    g.setFont(newFont);
                    g.setColor(Color.black);
                    g.drawString(text, 20, 20);
                g.setFont(oldFont);
                g.setColor(oldColor);
            }
        }
    

    Now, when I actually define my buttons, I do this. By providing the one line it needs, the only thing that makes it different from others. Now I could make a new file for each one, and define a new class for each one. This is much simpler.

    private static void loadButtonPanelButtons() {
        /* This button should tell the parent to bring up the save screen */
        TopButton save = new TopButton(buttonPanel,"Save") {
            public void triggerEvent() { parent.triggerSave(); }
        };
        save.setBorder(LineBorder.createBlackLineBorder());
        buttonPanel.add(save);
    
        /* This button should tell the parent to bring up the load screen */
        TopButton load = new TopButton(buttonPanel,"Load") {
            public void triggerEvent() { parent.triggerLoad(); }
        };
        load.setBorder(LineBorder.createBlackLineBorder());
        buttonPanel.add(load);
    
        TopButton addTile = new TopButton(buttonPanel,"Add Tile") {
            public void triggerEvent() { parent.triggerAddTile(); }
        };
        addTile.setBorder(LineBorder.createBlackLineBorder());
        buttonPanel.add(addTile);
    
        TopButton saveTiles = new TopButton(buttonPanel,"Save Tiles") {
            public void triggerEvent() { parent.triggerStyleSave(); }
        };
        saveTiles.setBorder(LineBorder.createBlackLineBorder());
        buttonPanel.add(saveTiles);
    }
    

    Now, when I handle the buttons being pressed, remember back in the definition of TopButton… there was

        public void mouseClicked(MouseEvent e) { triggerEvent(); }
    

    We know triggerEvent() eventually gets defined. We can define it on a per-button basis, and when the panel gets clicked, no matter what we defined triggerEvent() to be, it gets called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have text I am displaying in SIlverlight that is coming from a CMS
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.