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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:04:07+00:00 2026-05-23T16:04:07+00:00

I have an angle in a frame (I draw it with two lines). I

  • 0

I have an angle in a frame (I draw it with two lines). I want to make it flexible to frame; I mean, when the user expands the frame angle also become expanded and vice versa. I tried a lot of examples but I could not solve it. Can someone help?

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;

public class LineDraw extends Frame {
    Line2D line1 = new Line2D.Double(200, 200, 100, 300);
    Stroke drawingStroke1 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0,
            new float[] { 9 }, 0);
    Line2D line2 = new Line2D.Double(200, 200, 200, 300);

    public void paint(Graphics g) {
        Graphics2D graph = (Graphics2D) g;
        graph.setPaint(Color.red);
        graph.draw(line2);
        graph.setStroke(drawingStroke1);
        graph.setPaint(Color.green);
        graph.draw(line1);

    }

    public static void main(String args[]) {
        Frame frame = new LineDraw();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                System.exit(0);
            }
        });
        frame.setSize(300, 250);
        frame.setVisible(true);
    }
}
  • 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-23T16:04:07+00:00Added an answer on May 23, 2026 at 4:04 pm

    Here it is done in Swing. Everything is done in the EDT, as is intended with Swing as it is not thread safe. It is double buffered. Why the JLabel/Icon combination? It’s just the best way to do it, as far as I have discovered, and I’d struggle to give you a historical/technical explanation of why – that’s just the way it seems to have been designed. The other approach is to get involved with BufferStrategy but that starts to get more complicated IMHO.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    
    public class LineDrawSwing extends JLabel implements Icon {
        Line2D line1, line2;
    
        public LineDrawSwing() { this.setIcon(this); }
    
        Stroke drawingStroke1 = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0,
                new float[] { 9 }, 0);
    
        public static void main(String args[]) {
            JFrame frame = new JFrame();
            frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    System.exit(0);
                }
            });
            frame.add(new LineDrawSwing());
            frame.validate();
            frame.setSize(300, 250);
            frame.setVisible(true);
        }
    
        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Dimension size = getSize();
            line1 = new Line2D.Double(size.width/2, size.height-10, 10, 10);
            line2 = new Line2D.Double(size.width/2, size.height-10, size.width-10, 10);
            Graphics2D graph = (Graphics2D) g;
            graph.setPaint(Color.red);
            graph.draw(line2);
            graph.setStroke(drawingStroke1);
            graph.setPaint(Color.green);
            graph.draw(line1);
        }
    
        @Override
        public int getIconHeight() {
            return getSize().height;
        }
    
        @Override
        public int getIconWidth() {
            return getSize().width;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a space ship that I want to turn to a destination angle.
I have a point A, I also have the angle. I also have the
I have an Angle class that I want to behave like a float, with
I want to have a shortcut, RAlt+a, that simply sends the right angle quote,
I have a method that, given an angle for North and an angle for
I have a texture that follows a user's finger in GLKit. I calculate the
I want to draw a 3d line from one 3d point to another 3d
I have a variable that holds an angle, in degrees, which can be both
I have a base class called SpriteSheet which has two children, RotatedSpriteSheet and FlippedSpriteSheet.
Is it possible to have angle brackets in method names , e.g. : class

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.