黑马程序员技术交流社区
标题:
求大神指导,为什么没法做到两个窗体不同显示
[打印本页]
作者:
迷彩码农
时间:
2016-12-31 21:08
标题:
求大神指导,为什么没法做到两个窗体不同显示
package t1;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import javax.swing.JFrame;
//
//spin算法的主程序
public class spin {
public static void main(String[] args) {
int x =100,y=100;
test1 t1 = new test1();
t1.pmain();
testpaint testpaint1 = new testpaint();
//testpaint1.main2(x,y);
testpaint2 testpaint2 = new testpaint2();
testpaint2.main3(x+300,y);
}
}
//传感器节点
class point{
public int point_x;
public int point_y;
public char alive = 'a' ;
//构造探针并且对其随机覆盖位置
public point() {
point_x=(int)(Math.random()*100);
point_y=(int)(Math.random()*100);
}
}
//运算探针法 ,决定传感器的激活和暂停状态
class test1{
//移植区
static point pointlin[]=new point[300];
public static void maker() {
for(int i=0; i<300; i++)
{
pointlin[i] = new point();
}
}
//测试重复覆盖了没有
public static void testpoint_in(point point1, point point2) {
int _x = Math.abs(point1.point_x - point2.point_x);
int _y = Math.abs(point1.point_y - point2.point_y);
double doxy= Math.sqrt(_x * _x+_y * _y);
if(doxy<6){
point1.alive = 'b';
}
}
//判断是否传感器休眠外部循环
public static int testpoint(point pointline[]) {
//外循环要测试的点
for (int i = 0; i < pointline.length; i++) {
//内循环寻找探针PRB_RPY
if(pointline[i].alive =='a')
{
for(int j=i+1;j<pointline.length;j++)
{
if(pointline[j].alive =='a')
{
testpoint_in(pointline[i], pointline[j]);
}
if (pointline[i].alive =='b')
{
break;
}
}
}
}
return 0;
}
public static void pmain() {
maker() ;
testpoint(pointlin);
}
}
//绘制最后留下来的节点
class testpaint extends JFrame{
public testpaint(){
this.setTitle("保留的开机节点");
}
public void main2(int x,int y) {
testpaint t=new testpaint();
t.setLocation(x, y);
t.setSize(300, 300);
t.getContentPane().setBackground(Color.white);
t.setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
for (int i = 0; i < 300; i++) {
if(test1.pointlin[i].alive == 'a')
{
Ellipse2D e = new Ellipse2D.Double(test1.pointlin[i].point_x*3,test1.pointlin[i].point_y*3,20,20);
//加上下面这句就能变的圆滑了
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.black);
g2.draw(e);
}
}
}
}
//绘制整个区域的覆盖情况
class testpaint2 extends JFrame{
public testpaint2(){
this.setTitle("----覆盖情况显示----");
}
public void main3(int x,int y) {
testpaint t=new testpaint();
t.setLocation(x, y);
t.setSize(300, 300);
t.getContentPane().setBackground(Color.BLUE);
t.setVisible(true);
}
public void paint(Graphics g){
super.paint(g);
Graphics2D g2 = (Graphics2D)g;
for (int i = 0; i < 300; i++) {
if(test1.pointlin[i].alive == 'a')
{
Ellipse2D w = new Ellipse2D.Double(test1.pointlin[i].point_x*3,test1.pointlin[i].point_y*3,50,50);
//加上下面这句就能变的圆滑了
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.red);
g2.draw(w);
}
}
}
}
//显示传输结果借鉴testpointhanshu
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2