现在用NetBeans做一个Java的GUI开发,组件很多,把组件拉好后,只有一个主类很大,有什么方法把它分开
解决方案 »
- 看了马士兵的视频之后呢
- 高分求背包算法源代码:要求1、java代码(一楼提供的类即可) 2、必须用回溯法 3、不用递归用栈实现
- JDBC问题
- 请问高手,,如何学好JSP SERVLET??
- JAVA读写XML的问题(初级)
- 求救:谁有远程控制软件tightvnc源码,要java的,还得有模块划分和程序流程
- 这种情况怎么获取图片的宽度和高度呢?
- j2se1.4+j2me1.0.4遇到了乱码问题
- visual age for java 的使用
- java编辑编译器发布了,大家看看
- Java------程序人生----路漫漫其修远兮
- 像一个小区车辆管理系统这样的程序,如果画流程图,是不是要按照各个功能分着来画啊?
我想在你的介面上肯定有很多Panel.
不过反正是拖出来的,应该改的几率也不大吧,类大点就大点吧!
在最后的总显示类中把这些模块合并给个例子:
一个Bean/**
* A Bean used to show annotation file comboBox
* @author Marquis
* @version 1.0
*/
public class AnnotationBean extends JComponent {
private JComboBox annotationCmb;
private JLabel annotationLb; /**
* Constructor
*/
public AnnotationBean() {
super();
init();
} //=====public methods========= /**
* Set the selected annotation file with the name
*
* @param fileName file name
*/
public void setSelectedAnnotationFile(String fileName) {
annotationCmb.setSelectedItem(fileName);
} /**
* Set the selected annotation file with the index
*
* @param index the index of annotation files added in annotation comboBox
*/
public void setSelectedAnnotationFile(int index) {
annotationCmb.setSelectedIndex(index);
} /**
* @return the name of annotation file selected
*/
public String getSelectedAnnotationFileName() {
return StringUtils.deNull((String) annotationCmb.getSelectedItem());
}
/**
* This method gets the full path of the annotation file selected.
* @return
*/
public String getSelectedAnnotationFilePath()
{
return getSelectedAnnotationFile().getPath();
} /**
* @return the annotation file selected
*/
public File getSelectedAnnotationFile() {
String fileName = (String) annotationCmb.getSelectedItem();
if( StringUtils.isEmpty( fileName ) )
{
return null;
}
String filePath = User.getCurrentUser().getUserProfilerPath();
return new File(filePath + File.separator + fileName);
} /**
* get the annotation comboBox
*
* @return The Annotation ComboBox
*/
public JComboBox getAnnotationComboBox() {
return annotationCmb;
} /**
* Set ItemListener to annotation comboBox
*
* @param itemListener
*/
public void setAnnotationComboBoxListener(ItemListener itemListener) {
annotationCmb.addItemListener(itemListener);
} //====intenal methods==== /**
* initialize AnnotationComp
*/
protected void init() {
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.add(createAnnotationLabel());
this.add(createAnnotationComboBox());
for (Component c : this.getComponents()) {
((JComponent) c).setAlignmentX(Component.LEFT_ALIGNMENT);
}
} /**
* @return create a annotation label
*/
protected JLabel createAnnotationLabel() {
annotationLb = new JLabel();
annotationLb.setText(CytoMessage.getResourse("label.annotationComp.annotation"));
return annotationLb;
} /**
* @return JComboBox create a ComboBox with annotation files in user profile path
*/
protected JComboBox createAnnotationComboBox() {
annotationCmb = new JComboBox();
annotationCmb.setFocusable( true );
File userProfileDirectory = new File(User.getCurrentUser().getLibPath());
File[] annotationFiles = FileUtils.getFilesByType(userProfileDirectory, CytoConstant.ANNOTATION_FILE_EXTENSION); if (annotationFiles.length == 0) {//there are no .db files found in user profilerPath
//TODO Throw a fileNotFindException
return annotationCmb;
} for (File f : annotationFiles) {
annotationCmb.addItem(f.getName());
}
annotationCmb.setSelectedIndex(0);
return annotationCmb;
}}
最后在主显示界面中把bean进行组装 /**
* Create Main Panel
*/
@Override
protected void createMainPanel( JPanel mainPanel )
{
//other beans....
annotationComp = new AnnotationBean();
mainPanel.add( annotationComp );
}