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

  • SEARCH
  • Home
  • 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 8933347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:30:59+00:00 2026-06-15T09:30:59+00:00

I have a Java GUI program that simulates a simple text field(to be like

  • 0

I have a Java GUI program that simulates a simple text field(to be like sticky-notes). I want to be able to click the close button and it automatically saves it to a pre-defined text field in the directory.

But I am having trouble with static errors:

File: C:\Users\Adel\Code\Javas\popupText.java  [line: 538]
Error: non-static method open() cannot be referenced from a static context

Here is the main method of my program:

 public static void main(String args[])
  {
    popupText note = new popupText("Untitled-Notepad");
    note.setSize(600,600);
    note.setLocation(200,200);
    note.setVisible(true);

    WindowListener exitListener = new WindowAdapter() {

      @Override
      public void windowClosing(WindowEvent e) {
        int confirm = JOptionPane.showOptionDialog(null, "Are You Sure to Close Application?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (confirm == 0) {

          open();   //THIS CAUSES ERROR!!
          System.out.print("Yay I openeed");
          addToStatic();  //just added @ end
          System.exit(0);
        }
      }
    };
    text.append(guts);

    note.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
    note.addWindowListener(exitListener);

The text area is simple and looks like so, and if you like I can give the full code of that too(it’s just a bit unformatted at the moment):

enter image description here

  • 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-06-15T09:30:59+00:00Added an answer on June 15, 2026 at 9:30 am

    main is static, but the open method is not.

    You can only access static methods (and fields) from other static methods.

    Without further code, I suggest you try something like note.open() instead (assuming open is a method of note)

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

Sidebar

Related Questions

I have program in Java that I want to rewrite (GUI and some new
I have a simple Java program that reads in a text file, splits it
I have written a java program that is actually works as a gui to
Say I have a GUI Java project of something that simulates an ATM machine,
I have a Java program that is mostly GUI and it shows data that
I've got a nice text based java program that I'd like to add a
I have made a java GUI program and have added a jList on that
I have made a java program with GUI. Now I want to add a
I have made a java program with GUI and I want a stop button
I have a program with Driver GUI java file that creates a JFrame and

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.