Question
Given the following Java code how can I center on screen the graphics drawing made in a myPanel class? I just need a pseudo example
Given the following Java code how can I center on screen the graphics drawing made in a myPanel class? I just need a pseudo example since I cant post the whole code while enrolled in this class. import javax.swing.JFrame; public class Main { public static void main(String[] args) { JFrame myFrame = new JFrame("Minesweeper"); myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); myFrame.setLocation(400,150); myFrame.setSize(1920, 1080); //Hard coded Resolution myFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // sets Frame to full screen on launch MyPanel myPanel = new MyPanel(); myFrame.add(myPanel); MyMouseAdapter myMouseAdapter = new MyMouseAdapter(); myFrame.addMouseListener(myMouseAdapter); myFrame.setVisible(true); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started