I am new to GUI programming with java and some questions occured in my head. I am learning now the MVC-pattern and I was wondering how the implementation of a JFrame with a button to create squares on click would look like . What I want to do is : I have a Frame and a button, the button is pressed and a new square is randomly positioned on the screen, then i can drag it around in the frame and change its position and the console has an output : Square1 was moved to X Y (coordinates); Then ,if the button is pressed again, a new square is created (Square2). When I drag it, the console says : Square2 was moved to X Y .
Any suggestions what I should do in order to make that possible ? I know that my model is actually the square and its properties.My view is actually the JFrame with the button. But I do not know how to implement the controller, so that I can get the console outputs for the different objects..
Thank you !
答案 0 :(得分:0)
快速回答:
“您的java类中的主要方法可以充当您的控制器。 视图是页面,但你使用的是swing组件,所以在这种情况下你的视图就是这样。 “强>