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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:37:57+00:00 2026-06-12T01:37:57+00:00

Hello I am trying to draw diagonal lines in Java and this won’t work

  • 0

Hello I am trying to draw diagonal lines in Java and this won’t work like it should..

the “value” variable is beeing updated in a for loop each time but it gets the next value

for example if i insert a 1 i get this in my console with a system.out.println(value):

2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304

but the variable “value” has to contain the value i insert.. the code i use for this you can find below

DrawLines line = new DrawLines();
int value = 0;
public void paintComponent(Graphics g) {

    super.paintComponent(g);

    int xPos = 0;
    int yPos = getHeight() - (getHeight() / 2);

    for(int aantalLines = 0; aantalLines < 10; aantalLines++ ) {
        line.drawLines(g, xPos, yPos + value, getWidth(), getHeight() - value );
        value += value;
        System.out.println(value);
        System.out.println(aantalLines);
    }

}

public void actionPerformed(ActionEvent e) {

    try {
        value = Integer.parseInt(tussenRuimte.getText());
        repaint();
    }
    catch(NumberFormatException err) {
        JOptionPane.showMessageDialog(null, "Number Format Error: Vul alles goed in s.v.p");
    }

}

the problem is that it doesn’t work like this.. can someone explain what i do wrong and how to fix this?

  • 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-12T01:37:58+00:00Added an answer on June 12, 2026 at 1:37 am

    Why modifying the value of value while you already have a loop variable:

    for(int aantalLines = 0; aantalLines < 10; aantalLines++ ) {
      line.drawLines(g, xPos,       yPos +        ((aantalLines + 1) * value), 
                        getWidth(), getHeight() - ((aantalLines + 1) * value) );
    }
    

    which should come down to what @Hovercraft already suggested.

    If none of those solutions help, you probably have a problem somewhere else.

    Note: do not alter state in the paint, paintComponent, … methods. You have no control over how many times and when they are invoked

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

Sidebar

Related Questions

I'm trying to draw a text on Canvas like this (kinda pseudocode below): Paint
Hello I´m trying to automate AZURE VM management like Amazon EC2. Is there any
Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
I am just trying to add a Hello World or a program that draw
hello everyone im trying to create this tweak that copies a file from one
hello im trying to make something like github treeslider im new to javascript.. but
Hello Trying to sort this list by Month and day. Can not get it
Hello Im trying to get the value of an element from a JsonObject. i'm
I'm trying to draw simple 2d things in my JSP application. I found this
Hello i been trying to get a tokenizer to work using the boost library

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.