:( Sorry the topic spelled incorrectly.. I can't edit it noe.. sorry for that

Friends again need you so badly.. I'm developing my simple GIS application, actually here's what I developed so far..

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;


 class GUItest01 {

 

public void go(){
    JFrame frame = new JFrame("app");
    
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ImageIcon image = new ImageIcon("C:/icon.jpg");

    JLabel label = new JLabel(image);
    label.setPreferredSize(new Dimension(1200, 1000));
    JScrollPane jScrollPane = new JScrollPane(label);


    JPanel panel = new JPanel();

    

    frame.add(jScrollPane, BorderLayout.CENTER);
    //frame.setResizable(false);
   
    panel.setBackground(Color.cyan);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    JButton button = new JButton("Built Environment");
    JButton button1 = new JButton("Natural Environment");
    JButton button2 = new JButton("Roads Environment");
    JButton button3 = new JButton("Traffic Sensors");
    JButton button4 = new JButton("Refresh");

    panel.add(button);
    panel.add(button1);
    panel.add(button2);
    panel.add(button3);
    panel.add(button4);

    frame.getContentPane().add(BorderLayout.EAST,panel);
    frame.setSize(1500, 700);
    frame.pack();
    frame.setVisible(true);
    
    }


    public static void main(String[] args) {
        GUItest01 tg = new GUItest01();
        tg.go();
    }
}

I want to know how can I draw lines one the plane which the image on it.. there are many examples on the web but I can't find out how to implement those in this code.. please can you show me how to draw a single line.. thank you all

Edited 5 Years Ago by baby_c: n/a

can you show me how to draw a single line

Create a class that extends JPanel, override the paintComponent method,
add a call to the Graphics drawLine() to the paint method, add the panel to your GUI where you want to see the line.

Create a class that extends JPanel, override the paintComponent method,
add a call to the Graphics drawLine() to the paint method, add the panel to your GUI where you want to see the line.

thank you very much.. Can you just give a code example for that. I unable to code it thats ehy i'm asking.. thanks again

There must be code samples here on the Forum or Google.
Have you tried Searching here for drawLine?

Create a class that extends JPanel, override the paintComponent method,
add a call to the Graphics drawLine() to the paint method, add the panel to your GUI where you want to see the line.

What did you mean by "add the panel to your GUI where you want to see the line " ??

The "panel" refers to the class that extends JPanel. You add an instance of that class to a container in your GUI.
"Where you want to see the line" is the location on your GUI where you want to see the line.

Comments
thanks from Baby_C

The "panel" refers to the class that extends JPanel. You add an instance of that class to a container in your GUI.
"Where you want to see the line" is the location on your GUI where you want to see the line.

yeah.. got it.. thank you. I drew an oval...

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;


 class GUItest01 extends javax.swing.JFrame {



public GUItest01(){
    JFrame frame = new JFrame("GIS Application");

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ImageIcon image = new ImageIcon("C:/icon.jpg");

    JLabel label = new JLabel(image);

    label.setPreferredSize(new Dimension(1200, 1000));
    JScrollPane jScrollPane = new JScrollPane(new Image(image));


    JPanel panel = new JPanel();



    frame.add(jScrollPane, BorderLayout.CENTER);
    //frame.setResizable(false);
   
    panel.setBackground(Color.cyan);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    JButton button = new JButton("Built Environment");
    JButton button1 = new JButton("Natural Environment");
    JButton button2 = new JButton("Roads Environment");
    JButton button3 = new JButton("Traffic Sensors");
    JButton button4 = new JButton("Refresh");

    panel.add(button);
    panel.add(button1);
    panel.add(button2);
    panel.add(button3);
    panel.add(button4);

    frame.getContentPane().add(BorderLayout.EAST,panel);
    frame.setSize(1500, 700);
    frame.pack();
    frame.setVisible(true);


    }

class Image extends JLabel{

        public Image(ImageIcon image) {
            super(image);
        }
        @Override
     public void paintComponent(Graphics g){
             super.paintComponent(g);
            g.fillOval(400, 300, 50, 50);
    }


}

    public static void main(String[] args) {
        GUItest01 tg = new GUItest01();
        


    }
}
This article has been dead for over six months. Start a new discussion instead.