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 画的图出不来
------解决方案--------------------------------------------------------
布局管理器有问题,netbeans生成的代码和后面的使用add代码增加有冲突的