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
What effects will the different types of lighting produce on mountains?
bonufazy [111]
Once enough charge has been separated in a growing storm, a lightning flash can occur. These normally travel within or between clouds (abbreviated CC) or from cloud to ground (CG). Most storms produce more CC than CG flashes--about six times as many in tropical storms and two times as many in midlatitudes. Sometimes a flash will travel from cloud to air or simply occur within "clear" air.

Exactly what triggers flashes is still uncertain and an area of continued research. It seems that very concentrated electric fields (perhaps at the ends of pointed surfaces or single particles) are needed to accelerate charged particles, or ions. Once moving with sufficient energy, the ions appear to blaze a path toward opposite charge in cascading fashion.

3 0
3 years ago
How does social network use message to entertain?
Marizza181 [45]

Answer:

Explanation:

Social Network allows for easy creation of large groups of people that have the same tastes or are looking for the same thing. This allows for easy ways to entertain by providing what these individuals are looking for. Whether it is funny pictures, animal videos, news, celebrity videos, etc. Basically this ability to group individuals together by taste is what allows social networks to entertain through mass messaging in a way that is effective and gets the media in front of huge audiences.

3 0
3 years ago
Designer can be thought of as the ____ of video game development
Anna007 [38]
Your answer would be A. Architects 
8 0
4 years ago
Explain test-driven development and provide an example of how it can be used in your
dalvyx [7]

Answer:

 The test- driven development is basically use in the programming language for the designing various type of test cases in the computer system. The main goal of the test driven development is that it uses to make the system bug free and simple.

It basically use in the organization to avoid various duplication in the code and make the function more efficient.

The basic approach of the test driven development is that the test are develop so that it specify the function for the code to perform.

8 0
4 years ago
Something that requests data from a server is known as a ____.
rosijanka [135]

Answer:

It is  called a client.

Explanation:

Any entity that request data from a centralized node in a network (which is called a server, because once received a request, it replies sending the requested piece of data back to the requester) is called a client.

The server can adopt different names based on its role: It can be a file server, an application server, a web server, a mail server etc.

This sharing information paradigm, where the resources are located in one host (server) to be distributed to many hosts (clients)  is called client-server model.

3 0
3 years ago
Other questions:
  • You work as a network technician for uCertify Inc. You have erased data saved in your laptop. You still have many device configu
    6·1 answer
  • Successful attacks are commonly called ________. a. security incidents b. countermeasures c. both a and b d. neither a nor b
    10·1 answer
  • Why do we use console.log in javascript when changing variables?
    15·2 answers
  • A _______ is used to analyze and summarize your data without graphical support
    9·2 answers
  • Assume each student is assigned an advisor from a department. Each classroom is assigned a classroom (class# determines Classroo
    14·1 answer
  • 2. You can ___ adjust to NOT sleeping at night.
    13·1 answer
  • In cell E12, enter a formula to calculate the % of Budget by dividing the Actual expense by the Budget expense to indicate the p
    9·1 answer
  • Who wont me???????????????
    6·2 answers
  • Write the pseudocode for a program that will process attendance records of CA students. The students attend college five days a
    13·1 answer
  • the function must find the substrings of s that start with a vowel and end with a consonant, then print the alphabetically first
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!