温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何浅析Swing项目的开发

发布时间:2021-12-18 20:17:22 来源:亿速云 阅读:136 作者:柒染 栏目:编程语言

如何浅析Swing项目的开发,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

由于工作最近接手一个Swing项目,开发周期为一年,也算是不大不小的项目,而且项目由我来负责,(*^__^*) 嘻嘻……,我将我开发与管理的心得写下,欢迎各位高手和前辈批评指正。
项目开发前的准备:

a:首先对工具的现在,eclispe,netbeans,jb等,对于eclipse我们需要装一个插件swt-designer ,netbeans可以直接开发,sun公司为我们做好了,需要说的是eclipse不支持动态布局,但是将netbeans下的项目import到 eclipse下是可以运行的。

b:对于Swing项目来说,没有一个好的命名规范,特别是在多人参加开发,那将是很槽糕的,Swing中有大量的组件用起来也很麻烦,这里我写一个简单例子,比如,JTextField txtFieldName, JTextArea txtBlog,等,这样可以便于开发和交流。

c:对于工具的确定,netbeans做界面的开发比较好的选择但是对于后台的开发就显弱势了。在这里我选择eclipse作后台开发,最好将开发好的程序打jar文件***再导入netbeans中。

项目开发的相关设计

对于Swing做界面来说,并不是我们想象的那么容易,比如说我们在netbeans中画好了所有的界面,在你打开界面的源文件时你会发现这个文件很庞大,可能有上万行代码或者更多,当你读这个代码时也许会感觉茫然的哦。甚至有砸电脑的想法,当维护的人员看到这样的代码,我们是可以想象当时的情景,还有,在Swing中也有很多复杂的事件,对我们开发人员的本身也是一种挑战,我们必须在上万行代码中翻来找去,有没有什么好的办法来解决了。其实是有的。

我们开发其实是面对组件开发,然后将各个组件综合在一起就成了我们所需要的软件,当我们开发中肯定会遇到这样或者那样的
JPane ,JFrom JTable等,我们可以将一个个的jpane,jfrom jtable 重新组合中我们自己的组件以便复用,我们再这些组件综合在主要的Pane中下面的例子是我用netbeans开发的:

package singlepane;   import org.jdesktop.application.Action;  import org.jdesktop.application.ResourceMap;  import org.jdesktop.application.SingleFrameApplication;  import org.jdesktop.application.FrameView;  import org.jdesktop.application.TaskMonitor;  import java.awt.event.ActionEvent;  import java.awt.event.ActionListener;  import javax.swing.Timer;  import javax.swing.Icon;  import javax.swing.JDialog;  import javax.swing.JFrame;  import org.flybird.plat.SingleJpane;   /**  * The application's main frame.  */  public class SinglePaneView extends FrameView  {   public SinglePaneView(SingleFrameApplication app) {  super(app);   initComponents();  }   /** 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.   */  // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {   mainPanel = new javax.swing.JPanel();  mainPabbedPane = new javax.swing.JTabbedPane();  this.singleJpane = new SingleJpane();  savePanel = new javax.swing.JPanel();   mainPanel.setName("mainPanel"); // NOI18N   mainPabbedPane.setName("mainPabbedPane"); // NOI18N   savePanel.setName("savePanel"); // NOI18N   org.jdesktop.layout.GroupLayout savePanelLayout = new org.jdesktop.layout.GroupLayout(savePanel);  savePanel.setLayout(savePanelLayout);  savePanelLayout.setHorizontalGroup(  savePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)  .add(0, 371, Short.MAX_VALUE)  );  savePanelLayout.setVerticalGroup(  savePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)  .add(0, 273, Short.MAX_VALUE)  );   org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(singlepane.SinglePaneApp.class).getContext().getResourceMap(SinglePaneView.class);  mainPabbedPane.addTab(resourceMap.getString("savePanel.TabConstraints.tabTitle"), savePanel); // NOI18N  mainPabbedPane.addTab("single", this.singleJpane);   org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);  mainPanel.setLayout(mainPanelLayout);  mainPanelLayout.setHorizontalGroup(  mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)  .add(mainPanelLayout.createSequentialGroup()  .add(mainPabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)  .add(24, 24, 24))  );  mainPanelLayout.setVerticalGroup(  mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)  .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()  .add(20, 20, 20)  .add(mainPabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE))  );   setComponent(mainPanel);  }// </editor-fold>  // Variables declaration - do not modify   private javax.swing.JTabbedPane mainPabbedPane;  private javax.swing.JPanel mainPanel;  private javax.swing.JPanel savePanel;  // End of variables declaration   private SingleJpane singleJpane;   }

看完上述内容,你们掌握如何浅析Swing项目的开发的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI