Java homework help - How do i add a JPanel object to the CENTER of the JFrame object to produce the screenshot? SHOW PRO

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Java homework help - How do i add a JPanel object to the CENTER of the JFrame object to produce the screenshot? SHOW PRO

Post by answerhappygod »

Java homework help - How do i adda JPanel object to the CENTER ofthe JFrame object to produce thescreenshot?
Java Homework Help How Do I Add A Jpanel Object To The Center Of The Jframe Object To Produce The Screenshot Show Pro 1
Java Homework Help How Do I Add A Jpanel Object To The Center Of The Jframe Object To Produce The Screenshot Show Pro 1 (5.8 KiB) Viewed 40 times
SHOW PROOF WITH A SCREENSHOT IN YOUR ANSWER THANK YOU
import java.awt.*;
import java.awt.event.*;
class ProjRun {
ProjRun() {
System.out.println(
"hello");
new GUI();
}
}
// create class to display clicks
class MyFrame extends Frame {
// create 2 ints for x and y
int clickX;
int clickY;
public void paint(Graphics g) {
g.drawString(" " + clickX + ", " + clickY, clickX, clickY);
}
}
class GUI {
public GUI(){
MyFrame frame = new MyFrame();
frame.setSize(300,100);
frame.setTitle("title");
frame.setVisible(true);
// window listent to allow users to close frame
frame.addWindowListener(new Close());
// mouse listener so we can print points for mouse clicks
frame.addMouseListener(new MouseProc(frame));
}
}
// monitors closing window and extends WindowAdapter
class Close extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
// Monitor mouse clicks and gather x and y points
class MouseProc extends MouseAdapter {
MyFrame reference;
MouseProc(MyFrame winIn) {
reference = winIn;
}
@Override
public void mousePressed(MouseEvent e) {
reference.clickX = e.getX();
reference.clickY = e.getY();
reference.repaint();
}
}
DONT COPY + PASTE OR I WILL CONTACT answers ;D
Display your name here 1,8 X
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply