1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zlopas [31]
3 years ago
6

In java

Computers and Technology
1 answer:
Kisachek [45]3 years ago
7 0

Answer:

import javax.swing.JPanel;

import javax.swing.JOptionPane;

import javax.swing.JFrame;

import javax.swing.JLabel;  

import javax.swing.JTextField;

import javax.swing.border.Border;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.Rectangle;

public class DrawingPanel{

 

private static final int width = 800;

private static final int heigth = 500;

private static JFrame mainFrame;

private static JPanel mainPanel, inputPanel, drawPanel;

private static JLabel xLabel, yLabel;

private static JTextField xField, yField;

private static JButton drawButton;

 

public static void main(String[] args)

{

mainFrame = new JFrame("Draw Path");

mainPanel = new JPanel(new BorderLayout());

 

inputPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

xLabel = new JLabel("X Coordinate: ");

xField = new JTextField(5);

yLabel = new JLabel("Y Coordinate: ");

yField = new JTextField(5);

drawButton = new JButton("Draw");

inputPanel.add(xLabel);

inputPanel.add(xField);

inputPanel.add(yLabel);

inputPanel.add(yField);

inputPanel.add(drawButton);

 

Border border = BorderFactory.createLineBorder(Color.black);

drawPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

drawPanel.setBorder(border);

 

mainPanel.add(inputPanel, BorderLayout.NORTH);

mainPanel.add(drawPanel, BorderLayout.CENTER);

 

mainFrame.add(mainPanel);

mainFrame.setSize(PANEL_WIDTH, PANEL_HEIGHT);

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mainFrame.setLocationRelativeTo(null);

mainFrame.setResizable(false);

mainFrame.setVisible(true);

 

// action listener for draw button

drawButton.addActionListener(new ActionListener() {

(use the at sign here)Override

public void actionPerformed(ActionEvent e) {

if(xField.getText().equals("") || yField.getText().equals(""))

JOptionPane.showMessageDialog(null, "Please enter the x and y coordinates!");

else

{

int x2 = Integer.parseInt(xField.getText().trim());

int y2 = Integer.parseInt(yField.getText().trim());

if(x2 > WIDTH || y2 > HEIGHT)

JOptionPane.showMessageDialog(null, "x and y coordinates should be less than "

+ width + " and " + height + " respectively!");

else

drawPath(x2, y2);

}

}

});

}

 

public static void drawPath(int x2, int y2)

{

int x1 = (int)drawPanel.getBounds().getCenterX();

int y1 = (int)drawPanel.getBounds().getCenterY();

 

Graphics g = drawPanel.getGraphics();

Rectangle r = drawPanel.getBounds();

g.setColor(drawPanel.getBackground());

g.fillRect(r.x, r.y, r.width, r.height);

 

g.setColor(Color. blue);

g.drawLine(x1, y1, x2, y2);

}

}

Explanation:

The class DrawingPanel is a Java class that gets the user input for the coordinate of a path with predetermined heigth and width (defined in the class). The methods of the class are; getGraphics(), getBounds(), getBackground(), setColor() and fillRect(). The result is a rectangular path GUI on the screen.

You might be interested in
You are flying an aircraft equipped with an electronic flight display and the air data computer fails. What instrument is affect
Makovka662 [10]

Answer:

cause loss of power, excessive oil consumption, and possible permanent internal engine damage.

Explanation:

4 0
3 years ago
Netiquette is the
e-lub [12.9K]

Answer:

C

Correct or acceptable way of communicating

4 0
3 years ago
What types of company functions are aided by ERP?
Jet001 [13]

Answer:

These activities include <u>accounting, project management, attendance management, managing merchant details, attendance management, compliance and employee management.</u>

7 0
2 years ago
Cuando hablamos de entornos digitales de enseñanza aprendizaje a que nos estamos refiriendo
olga2289 [7]

Answer:

Al hablar de entornos digitales de enseñanza y aprendizaje, la frase apunta al avenimiento de medios informáticos y tecnológicos al proceso metodológico de enseñanza de los distintos sistemas educativos a nivel mundial.

Así, la irrupción del internet como medio de búsqueda de información y las herramientas digitales como vídeos, diapositivas y libros electrónicos como métodos de presentación de información han facilitado el acceso de los alumnos y docentes al conocimiento a través de la generación de un entorno digital que permite a estos un acceso mas rápido y abarcativo al conocimiento.

7 0
3 years ago
A provides an easy way for workers to interact with their computers
LenKa [72]

<u>Answer:</u>

<em>GUI provides simple and easy way to operate computers. </em>

<u>Explanation:</u>

Before <em>GUI there were only CUI (Character User Interface) where the user needs to remember lots of commands to interact with computer </em>and it is also time consuming.

<em>Eg. DOS (Disk Based Operating System). </em>

This problem was overcome by GUI where it contains buttons where the user can use the <em>mouse to click, double click or right click </em>according to the options provided by the environment. <em>GUI is the successor of CUI.</em>

7 0
3 years ago
Other questions:
  • Which are the common database operations that can help organize data for easy retrieval?
    13·1 answer
  • Which of the following could be useful during system testing?
    6·1 answer
  • Suppose a program takes 1000 machine instructions to run from start to end, and can do that in 10 microseconds when no page faul
    9·1 answer
  • Write a program that takes a three digit number (input) and prints its ones, tens and hundreds digits on separate lines
    14·1 answer
  • Why is know app downloading in my android phone even if I have 900 MB ???
    8·2 answers
  • Match each item with a statement below. - A popular port scanners that has the ability to use a GUI front end - Allows you to pi
    8·1 answer
  • Which of the following is a capital resource a computer programmer
    15·1 answer
  • To edit the color of the text in Word Online, choose the Font color command under what tab?
    8·1 answer
  • Provide 10 points for each question
    6·1 answer
  • bookmark question for later what database did zach choose? microsoft excel microsoft access db2 oracle
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!