为什么画图显示不出来呢?

fengzhe0411 2009-08-19 10:13:23

import java.awt.*;
import java.awt.geom.Rectangle2D;
import javax.swing.*;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* MyJframe.java
*
* Created on 2009-8-19, 9:24:05
*/

/**
*
* @author Administrator
*/
public class MyJframe extends javax.swing.JFrame {

/** Creates new form MyJframe */
public MyJframe() {
initComponents();
DrawComponent component=new DrawComponent();
add(component);
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 102));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setLocationByPlatform(true);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 427, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 372, Short.MAX_VALUE)
);

pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyJframe().setVisible(true);
}
});
}

// Variables declaration - do not modify
// End of variables declaration

}

class DrawComponent extends JComponent{
public void paintComponent(Graphics g){
Graphics2D g2=(Graphics2D)g;
Rectangle2D rect=new Rectangle2D.Double(100,100,200,200);
g2.setPaint(Color.ORANGE);
g2.fill(rect);
}
}



如题啊..只能显示一个frame 画的图出不来
...全文
333 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
congjiao1988 2012-10-06
  • 打赏
  • 举报
回复
我现在也遇到这种情况,不知道您知道如何解决了吗
fengjian120823657 2009-10-05
  • 打赏
  • 举报
回复
真的假的,我也搞不清楚,NetBeans自动生成的代码和手写的怎么才能合理的搭配!
daimojingdeyu 2009-08-20
  • 打赏
  • 举报
回复
下面两行去掉
DrawComponent component=new DrawComponent();
add(component);
将DrawComponent放到一个单独的类中,然后从源码处将DrawComponent类拖到JFrame上

试试应该可以的
fengzhe0411 2009-08-20
  • 打赏
  • 举报
回复
那我应该怎么办...手写吗...我多想拖拽完成啊...
daimojingdeyu 2009-08-19
  • 打赏
  • 举报
回复
布局管理器有问题,netbeans生成的代码和后面的使用add代码增加有冲突的
fengzhe0411 2009-08-19
  • 打赏
  • 举报
回复
在线等...
fengzhe0411 2009-08-19
  • 打赏
  • 举报
回复
无言了...没人来答...

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧