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 6690669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:39:50+00:00 2026-05-26T05:39:50+00:00

I have a problem with an action listener after I draw a line, basicly

  • 0

I have a problem with an action listener after I draw a line, basicly it works just one time, for example, my application is downloading an image, than u pick two points, first with left button mouse, second with right button, than u click “connect points” button, and it is drawing a line. And this works, I can do it with many lines etc. BUT when I close an window with image and reload it the “connect points” button stops working. Dk what to do with it. Here is the code:

the painting line part:

public void paint(Graphics g) {

 super.paint(g);
    myPaint(g);  
 }

 private void myPaint(Graphics g) {
    g.drawLine(lx1, ly1, px2, py2);
 }
}

ActionListener part:

public void actionPerformed(ActionEvent e) {

    if(e.getSource()==painterka){

       Graphics g = imadzysko.getGraphics();
          paint(g);
            lx1=0;
            ly1=0;
            px2=0;
            py2=0;    
       }
 }

Panel with graphic part:

void diagramKY (JFrame windower, String tyt, String content) {
    Listener listener = new Listener(); 

    panelik.setLayout(null);
    painterka =  new JButton("Connect Points");
    windower = new JFrame("");
    windower.setTitle(tyt+" - diagram");
    windower.setSize(800, 600);
    windower.setVisible(true);
    windower.setLocationRelativeTo(null);
    URLdownloader.fileUrl("http://stooq.pl/c/?s="+content+"&c=1d&t=l&a=lg",
             content+".png","");
    imadzysko = new ImagePanel(new ImageIcon(content+".png").getImage());
    panelik.add(imadzysko);
    panelik.add(painterka);
    imadzysko.addMouseListener(new MyMouseListener());
    painterka.addActionListener(listener);
    Insets insets = panelik.getInsets();
    Dimension size = imadzysko.getPreferredSize();
    imadzysko.setBounds(20 + insets.left, 20 + insets.top,
        size.width, size.height);
    size = painterka.getPreferredSize();
    painterka.setBounds(630 + insets.left, 20 + insets.top,
        size.width, size.height);
    panelik.repaint();
    imadzysko.repaint();
    windower.add(panelik);

well, any suggestions? 🙂

  • 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-26T05:39:51+00:00Added an answer on May 26, 2026 at 5:39 am

    1) create panel, put that to the GUI and last code lines would be

    windower.setLocationRelativeTo(null);
    windower.setVisible(true);
    

    otherwiese your panel never will be visible on the screen

    2) don’t use setBounds() etc.., for that is there exists LayoutManagers

    windower.add(panel);
    

    then your panel fill whole JFrame area

    3) never use paint(Graphics g) in the Swing Code, use only paintComponent(Graphics g) to avoids un-expected output to the GUI

    4) don’t create new Top-level Containers on Runtime, for popup window create only one JDialog or JWindow and re-use that for another Action

    5) you have problems with Concurency in Swing, your GUI freeze, because waiting for hard and longtime code, implements SwingWorker, there is similair example about that

    6) if you want to display some pictures or images look for Icon placed in the JLabel

    7) really required to read 2D Graphics tutorial before posting question here

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

Sidebar

Related Questions

I have a problem with Jquery function getJSON, the action url does not trigger
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I'm struggling here with a problem: I have a controller questions which has action
I have a problem with initializing my app properly after the autostart. I've managed
Alright, so heres my problem: I have an application I am working with that
I'm working on a Java Swing application. I have a button whose action runs
Here's my problem: I have do create a menu/list of actions (which would be
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am

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.