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]
2 years ago
6

In java

Computers and Technology
1 answer:
Kisachek [45]2 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
What date of us can be used on a desktop computer
Alborosie

Answer:

Homie

Explanation:

yo my names Kai litty

5 0
3 years ago
How does the dns help the world wide web scale so that billions of users can access billions of web pages?.
valentina_108 [34]

Answer:

domain name systems allow web users to choose where they want to go and to have many different sites

8 0
2 years ago
The rock cycle _____.
creativ13 [48]
The best and most correct answer among the choices provided by the question is the second choice. The rock cycle <span>changes and recycles Earth's rocks. </span>I hope my answer has come to your help. God bless and have a nice day ahead!
8 0
3 years ago
g Which statement is true about the difference between combinational logic circuits and sequential logic circuits? A) Combinatio
kogti [31]

Answer:

D.

Explanation:  

In combinational circuits, the current output values are always the same for the same set of input values, regardless the previous values.

We say that combinational circuits have no memory, or that the circuit has no feedback from the outputs.  

For sequential circuits, on the contrary, the current output values are not based in the current input values only, but on the previous output values as well.

So, the fact of having a defined set of input values at a given moment, doesn't guarantee which the output values will be.

We say that sequential circuits have memory, or that they have feedback from the outputs.

Examples of these type of circuits are R-S, J-K, D or T flip-flops.

4 0
2 years ago
___ is code that runs when a specific event happens.
Slav-nsk [51]
A callback function is code that's called, or run, when a specific event such as a click of the mouse, happens.Callback is another name for a callback function. Thank you for posting your question here at brainly. I hope the answer will help you. Feel free to ask more questions.
6 0
2 years ago
Other questions:
  • What is another name for “low-angle lighting”? Side lighting Top lighting Under-lighting Three-point lighting
    15·2 answers
  • WILL GIVE BRANLYIST
    6·1 answer
  • To find temporary windows files begin by typing in the search box
    6·1 answer
  • In cell h15 enter a vlookup function to determine the 2018 percentage of total attendance for the city listed in cell h14. Use t
    7·1 answer
  • Jennifer's company currently uses Windows Active Directory to provide centralized authentication, authorization, and accounting
    14·1 answer
  • The four key stages with regards to data visualization workflow. Select one key stage and explain it briefly about that stage.St
    10·1 answer
  • The entire presentation can be seen at a time in __________
    5·1 answer
  • In batch operating system three job J1 J2 and J3 are submitted for execution each job involes an I/O activity a CPU time and ano
    13·1 answer
  • Site at least 3 articles of impact of internet that affect in our daily lives.
    15·1 answer
  • How can a user access the Mailbox Cleanup tools?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!