高手帮忙看一下吧

寂寞灵魂 2012-10-11 08:47:13
怎么MyPanel显示不出来?帮忙看一下...在线等..
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CADTest extends JFrame {

JPanel doPanel,contentPane;
JLabel x1,x2,x3,y1,y2,y3,xx1,xx2,xx3,yy1,yy2,yy3,original,changed,symmetry,title;
JTextField fx1,fx2,fx3,fy1,fy2,fy3,fxx1,fxx2,fxx3,fyy1,fyy2,fyy3,enlargeNum,rotationNum;
JButton enter,symmetryX,symmetryY,symmetryO,enlarge,rotation;
GridBagLayout layout;
GridBagConstraints constraints;

public CADTest() {


contentPane = new JPanel();
doPanel = new JPanel();

fx1 = new JTextField(3);
fx2 = new JTextField(3);
fx3 = new JTextField(3);
fy1 = new JTextField(3);
fy2 = new JTextField(3);
fy3 = new JTextField(3);
fxx1 = new JTextField(3);
fxx2 = new JTextField(3);
fxx3 = new JTextField(3);
fyy1 = new JTextField(3);
fyy2 = new JTextField(3);
fyy3 = new JTextField(3);
enlargeNum = new JTextField(7);
rotationNum = new JTextField(7);

x1 = new JLabel("x1");
x2 = new JLabel("x2");
x3 = new JLabel("x3");
y1 = new JLabel("y1");
y2 = new JLabel("y2");
y3 = new JLabel("y3");
xx1 = new JLabel("x1");
xx2 = new JLabel("x2");
xx3 = new JLabel("x3");
yy1 = new JLabel("y1");
yy2 = new JLabel("y2");
yy3 = new JLabel("y3");
original = new JLabel("原始的坐标");
changed = new JLabel("改变后的坐标");
symmetry = new JLabel("对称变换");
title = new JLabel("CDA");

enter = new JButton("确定");
symmetryX = new JButton("沿X对称");
symmetryY = new JButton("沿Y对称");
symmetryO = new JButton("沿原点对称");
enlarge = new JButton("放大倍数");
rotation = new JButton("旋转角度");

layout = new GridBagLayout();
constraints = new GridBagConstraints();

doPanel.setLayout(layout);
//doPanel.setBorder(null);

constraints.fill = GridBagConstraints.VERTICAL;
addComponent(title,0,0,14,1);
addComponent(original,1,0,1,1);
addComponent(x1,1,1,1,1);
addComponent(fx1,1,2,1,1);
addComponent(x2,1,3,1,1);
addComponent(fx2,1,4,1,1);
addComponent(x3,1,5,1,1);
addComponent(fx3,1,6,1,1);
addComponent(y1,1,7,1,1);
addComponent(fy1,1,8,1,1);
addComponent(y2,1,9,1,1);
addComponent(fy2,1,10,1,1);
addComponent(y3,1,11,1,1);
addComponent(fy3,1,12,1,1);
addComponent(enter,1,14,1,1);

addComponent(changed,2,0,1,1);
addComponent(xx1,2,1,1,1);
addComponent(fxx1,2,2,1,1);
addComponent(xx2,2,3,1,1);
addComponent(fxx2,2,4,1,1);
addComponent(xx3,2,5,1,1);
addComponent(fxx3,2,6,1,1);
addComponent(yy1,2,7,1,1);
addComponent(fyy1,2,8,1,1);
addComponent(yy2,2,9,1,1);
addComponent(fyy2,2,10,1,1);
addComponent(yy3,2,11,1,1);
addComponent(fyy3,2,12,1,1);

addComponent(symmetry,3,0,1,1);
addComponent(symmetryX,3,1,1,1);
addComponent(symmetryY,3,2,1,1);
addComponent(symmetryO,3,3,1,1);

addComponent(enlarge,4,0,1,1);
addComponent(enlargeNum,4,1,1,1);
addComponent(rotation,4,2,1,1);
addComponent(rotationNum,4,3,1,1);

doPanel.setBounds(0,0,700,165);
contentPane.add(doPanel);

MyPanel myP = new MyPanel();
myP.setBounds(0,165,700,400);
contentPane.add(myP);
//setUndecorated(true);

getContentPane().add(contentPane);

this.update(this.getGraphics());
contentPane.repaint();
//pack();

setTitle("CADTest");
setBounds(100,100,700,565);
//setResizable(false);
setVisible(true);

}

private void addComponent(Component component,int row,int column,int width,int height){

constraints.gridx = column;
constraints.gridy = row;
constraints.gridwidth = width;
constraints.gridheight = height;

layout.setConstraints(component, constraints);
doPanel.add(component);

}

public static void main(String[]args){
CADTest application = new CADTest();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}



}

class MyPanel extends JPanel {

int x,y;

public MyPanel() {
addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
x = getX();
y = getY();
JOptionPane.showMessageDialog(null, "ja");
}
});
}


public int getXer() {
return x;
}
public int getYer() {
return y;
}

public void paintComponent(Graphics g) {
g.drawLine(0, 165, 700, 165);
g.drawLine(0, 365, 700, 365);
g.drawLine(350, 165, 350, 565);
}
}
...全文
155 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
寂寞灵魂 2012-10-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

把你的添加面板的代码改成这样,再把其他的代码添加到两个小的面板中就行了

MyPanel myP = new MyPanel();

add(myP); // 这儿

myP.setBounds(0,165,700,400);



d……
[/Quote]
我是想把myP和doPanel添加到contentPane里的..
zhaoming262350 2012-10-11
  • 打赏
  • 举报
回复
把你的添加面板的代码改成这样,再把其他的代码添加到两个小的面板中就行了

MyPanel myP = new MyPanel();

add(myP); // 这儿

myP.setBounds(0,165,700,400);



doPanel.setBounds(0,0,700,165);
myP.add(doPanel);


//setUndecorated(true);

myP.add(contentPane);

this.update(this.getGraphics());
内容概要:本文档系统讲解了创意版烟花的完整实现路径,从粒子系统原理出发,深入剖析烟花效果的五大核心阶段——上升、爆炸、扩散、衰减与拖尾,并基于四种技术栈(HTML5 Canvas、Three.js、Python Pygame、AI音乐节拍同步)提供可运行的完整代码方案。文档涵盖基础实现、视觉增强(形状变化、闪烁、二次爆炸)、交互升级(鼠标拖动、手势控制)、性能优化(对象池、渲染优化)、部署上线(GitHub Pages、Vercel)及创意拓展(文字烟花、数据可视化、协同互动),形成“原理→编码→调优→部署→创新”的闭环学习链路。同时融入Web Audio API节拍检测、滑动窗口动态阈值等实用算法,助力开发者打造兼具美观性与技术深度的动态视觉作品。; 适合人群:具备基础编程能力的前端开发者、Python爱好者、多媒体交互设计人员,以及希望提升图形编程与动效设计能力的工作1-3年研发人员;也适用于教学演示、作品集建设或创意项目原型开发。; 使用场景及目标:①掌握粒子系统在动画与游戏开发中的底层实现机制;②实现网页端与桌面端的高性能烟花特效;③构建音乐可视化、数据艺术、互动装置等融合型项目;④学习从代码实现到线上部署的全流程工程实践。; 阅读建议:建议按照“Canvas基础→进阶优化→3D/Pygame/AI扩展”的路径逐步实践,重点关注参数调优表与性能优化策略,在调试中理解每行代码的作用;对于音乐同步等复杂功能,可先运行成功案例再深入算法逻辑,结合实际项目需求灵活组合各项技术模块。

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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