Java homework help - How do i adda JPanel object to the CENTER ofthe JFrame object to produce thescreenshot?
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
Java homework help - How do i add a JPanel object to the CENTER of the JFrame object to produce the screenshot? SHOW PRO
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am