已解决问题
谷歌tunglin22用户在2013.05.02提交了关于“逸动j**a简单画线程序”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-09-01T14:33:45。希望大家能够帮助她。详细问题描述及疑问:期待您的答案,你无异于雪中送炭,让我感激涕零 !
详细问题描述及疑问:期待您的答案,你无异于雪中送炭,让我感激涕零 !
这个覆盖paint方法就可以了。
我帮你写好了,我采用的
下面是两个文件,第一个MyFrame是一个完整的工粳MyF
然后第二个是测试类,
------------------------
packageui;
importj**a.
importj**ax.swing.*;
importj**a.util.*;
classM
privateVector<JComponent>comps;
publicMyPanel(
comps=newVe
setLayout(**ll);
}
publicvoidpaint(Graphi
g.setColor(Color.BLACK);
for(inti=1;i<comps.size();
g.d
comps.get(0)
comps.get(i).getLoc
comps.get(i).getLoca
}
super.paintC
}
publicvoidaddComp
comp.setOpaque(true);
comps.add(comp);
add(comp);
repa
}
}
publicclassMyFrameextend
privateM
publicMy
setDefaultCloseOperation(JFrame
mp=ne
setContentPane(mp);
}
publicvoidaddCompo
mp
}
}
----------------
importui.*;
importj**ax.swing.*;
importj**ax.swing.border.*;
publicclassTestMyFrame{
publicstaticvoidmain(Stringargs[]){
MyFramemf=newMyFrame();
mf.setSize(500,500);
mf.setLocationRelativeTo(**ll);
mf.setVisible(true);
testAddComponent(mf);
}
publicstaticvoidtestAddComponent(MyFramemf){
JLabell1=newJLabel("l1");
l1.setBorder(newEtchedBorder());
l1.setBounds(200,100,20,20);
mf.addComponent(l1);
JLabell2=newJLabel("l2");
l2.setBounds(100,150,20,20);
l2.setBorder(newEtchedBorder());
mf.addComponent(l2);
JLabell3=newJLabel("l3");
l3.setBounds(150,150,20,20);
l3.setBorder(newEtchedBorder());
mf.addComponent(l3);
JLabell4=newJLabel("l4");
l4.setBounds(200,150,20,20);
l4.setBorder(newEtchedBorder());
mf.addComponent(l4);
}
}