码迷,mamicode.com
首页 > 编程语言 > 详细

201671010131 2016-2017-2 《Java程序设计》

时间:2017-11-13 00:11:57      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:信息   frame   default   str   line   style   def   event   多层   

本周学习了图形程序设计。

基本内容有:简单的图形框架的构建。

EventQueue.invokeLater(() ->
{
SimpleFrame frame = new SimpleFrame();

frame.setTitle();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});

private static String message;

public static String getMessage() {
return message;
}
public SimpleFrame()
{
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}

图形提示语的编写: fra.setTitle("welcome!");//窗口提示语

框架定位:

// set frame width, height and let platform pick screen location

setSize(screenWidth /2, screenHeight /2);//长,宽,为屏幕的一半,
setLocationByPlatform(true);//决定框架所放的位置。

在组件中显示信息:

public void paintComponent(Graphics g)//描述绘制组件的方法。
{
Graphics2D g2 = (Graphics2D) g;

// draw a rectangle

double leftX = 100;
double topY = 100;
double width = 200;
double height = 150;。。。。}

还有组件中图形的构建:

public DrawFrame()
{
add(new DrawComponent());//将一个给定组件添加到内容窗格中,本题为矩形。
pack();//调整窗口大小。
}

Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
g2.draw(rect);

 g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height));//。左上角的位置和长高。

可以生成多个窗口,但是不能做成多层的。

201671010131 2016-2017-2 《Java程序设计》

标签:信息   frame   default   str   line   style   def   event   多层   

原文地址:http://www.cnblogs.com/tgg1314/p/7823426.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!