import javax.swing.JFrame;
@SuppressWarnings("serial")
public class DisplaySurface extends JFrame
{ public DisplaySurface()
{
super();
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//客户区大小
this.setSize(600+4+4, 400+30+4);
//加载绘图Panel
this.add(new DrawPanel());
//不可改变大小
this.setResizable(false);
//设置标题
this.setTitle("MandelProb");
//显示
this.setVisible(true);
// TODO Auto-generated constructor stub
} /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
DisplaySurface tempFrame = new DisplaySurface(); }}
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel
{
public DrawPanel()
{
this.setSize(600, 400);
//this.setBackground(Color.BLACK);
this.setVisible(true);
} /* (non-Javadoc)
* @see javax.swing.JComponent#print(java.awt.Graphics)
*/
@Override
public void print(Graphics g)
{
// TODO Auto-generated method stub
super.print(g);
g.fillRect(50,100,100,100); g.drawString("dfsfsdfsdf", 100, 100);
}}
@SuppressWarnings("serial")
public class DisplaySurface extends JFrame
{ public DisplaySurface()
{
super();
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//客户区大小
this.setSize(600+4+4, 400+30+4);
//加载绘图Panel
this.add(new DrawPanel());
//不可改变大小
this.setResizable(false);
//设置标题
this.setTitle("MandelProb");
//显示
this.setVisible(true);
// TODO Auto-generated constructor stub
} /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
DisplaySurface tempFrame = new DisplaySurface(); }}
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel
{
public DrawPanel()
{
this.setSize(600, 400);
//this.setBackground(Color.BLACK);
this.setVisible(true);
} /* (non-Javadoc)
* @see javax.swing.JComponent#print(java.awt.Graphics)
*/
@Override
public void print(Graphics g)
{
// TODO Auto-generated method stub
super.print(g);
g.fillRect(50,100,100,100); g.drawString("dfsfsdfsdf", 100, 100);
}}
解决方案 »
- 学到什么阶段才能做软件呢?
- 新出炉的一个话费分析小程序
- 郁闷,再搞两天我就挂了。
- xml文件快速检索某个节点问题,在线等,谢谢
- 一个很简单的逻辑题
- 请问RetroGuard最新的版本是多少?哪里有下载的?
- 为什么要这么写?谁能告诉我?
- 侃侃、谈谈。
- 安装jbuilder4.0 后,它问我要序列号和key:的东西,可是找了很久也没有找到,请各位帮个忙吧?小弟在这里谢过了!
- 为什么覆盖override方法的可见性不可以降低,这样做有什么意义呢?java
- jxl读excel文件出错,jxl.read.biff.BiffException: Unable to recognize OLE stream
- java调用mysql的存储过程脚本
@Override
public void print(Graphics g)
{
// TODO Auto-generated method stub
super.print(g);
g.setColor(Color.white);
g.fillRect(50,100,100,100);
g.setColor(Color.black); g.drawString("dfsfsdfsdf", 100, 100);
}
this.getContentPane().add(你的panel)
重写paint()方法是awt的重量级重绘,不是好选择!