renolutmon.rar

  • 许江杰
    了解作者
  • Java
    开发工具
  • 2KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 3
    下载次数
  • 2017-07-08 20:59
    上传日期
这是我在培训时候作MVC例子时候编写的,旨在让大家认识这种模式,
renolutmon.rar
  • domain
  • Student.java
    382B
  • gui
  • GUI.java
    3.3KB
  • ModelImpl.java
    1.1KB
  • YController.java
    255B
  • Model.java
    343B
  • 2ControllerImpl.java
    603B
  • View.java
    314B
  • ViewImpl.java
    1.9KB
内容介绍
package mvc.gui; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import javax.swing.table.*; import java.util.*; public class GUI extends JFrame { JLabel labelStatue = new JLabel(); JToolBar toolBar1 = new JToolBar(); JLabel labelText = new JLabel(); JTextField textFieldName = new JTextField(); JButton buttonInsert = new JButton(); JScrollPane jScrollPane1 = new JScrollPane(); JLabel labelId = new JLabel(); JTextField textFieldId = new JTextField(); JTable tableContent = new JTable(); public GUI() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } this.setSize(600,500) ; this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ hide(); System.exit(0) ; } }) ; show(); } public static void main(String[] args) { GUI GUI1 = new GUI(); } private void jbInit() throws Exception { labelStatue.setText("jLabel1"); labelText.setText("Name"); textFieldName.setText("jTextField1"); buttonInsert.setText("Insert"); //buttonInsert.addActionListener(new GUI_buttonInsert_actionAdapter(this)); labelId.setText("ID"); textFieldId.setText("jTextField1"); toolBar1.add(labelId, null); toolBar1.add(textFieldId, null); toolBar1.add(labelText, null); toolBar1.add(textFieldName, null); toolBar1.add(buttonInsert, null); this.getContentPane().add(labelStatue, BorderLayout.SOUTH); this.getContentPane().add(toolBar1, BorderLayout.NORTH); this.getContentPane().add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.getViewport().add(tableContent, null); //jScrollPane1.getViewport().add(jTable1, null); } public void register(ActionListener [] al,ListSelectionListener [] lslList,TableModel tableModel){ buttonInsert.addActionListener(al[0]) ; this.tableContent .getSelectionModel() .addListSelectionListener(lslList[0]) ; tableContent.setModel(tableModel) ; tableContent.getSelectionModel() .setSelectionMode(ListSelectionModel.SINGLE_SELECTION ) ; } public void setTextFieldName(String str){ this.textFieldName .setText(str) ; } public String getTextFieldName(){ return this.textFieldName .getText() ; } public void setTextFieldId(String str){ this.textFieldId .setText(str) ; } public String getTextFieldId(){ return this.textFieldId .getText() ; } public void setTableContent(){ //this.listContent .setListData(strList) ; this.tableContent .updateUI() ; } public void setLabelStatue(Object obj){ this.labelStatue .setText(""+obj) ; } public Object getSelectedItem(){ //int index=this.listContent .getSelectedIndex() ; int index=this.tableContent .getSelectedRow(); if(index<0) return null; return ((mvc.ModelImpl )this.tableContent.getModel()) .getRowItem(index) ; //return str; } public void setSelectedItem(){ this.tableContent .changeSelection(this.tableContent .getModel() .getRowCount()-1,-1,true,false) ;//setSelectedIndex(this.tableContent .getModel() .getRowCount() -1 ) ; //this.tableContent.updateUI() ; } }
评论
    相关推荐