projectList.addPropertyChangeListener(JProjectList.SELECTED, todoList);
projectList.addPropertyChangeListener(JProjectList.SELECTED, activityList);应该是这两句
具体实现应该在todoList和activityList中好像涉及到bean了,用于动态刷新swing,有再完整点的代码么,学习学习
projectList.addPropertyChangeListener(JProjectList.SELECTED, activityList);应该是这两句
具体实现应该在todoList和activityList中好像涉及到bean了,用于动态刷新swing,有再完整点的代码么,学习学习
解决方案 »
- 为什么是这样呀
- clone()方法复制Spring容器中的bean,比如SessionFactory,那么这个克隆的对象,会受到Spring容器管理吗?求大虾指教!!!
- Vector 为什么线程安全
- 急,急,急,急,急,急,
- taglib directive for "bean" does not exist or Tld is not found是什么原因?
- 一个换码符“\”的问题
- 请问哪儿有JBuilder9.0和 Oracle8.0下载?急
- 5~~~~~~~~~~,项目完成,身心俱疲,散分!!!
- 是Exception还是Throwable表示所有异常的基类
- JAVA
- 下拉列表
- ORACLE数据插入问题
String propertyName,
PropertyChangeListener listener) {
if (listener == null) {
return;
}
if (changeSupport == null) {
changeSupport = new SwingPropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(propertyName, listener);
}
---------------------------------------changeSupport.addPropertyChangeListener的addPropertyChangeListener方法如下:public synchronized void addPropertyChangeListener(
String propertyName,
PropertyChangeListener listener) {
if (children == null) {
children = new java.util.Hashtable();
}
SwingPropertyChangeSupport child =
(SwingPropertyChangeSupport)children.get(propertyName);
if (child == null) {
child = new SwingPropertyChangeSupport(source);
children.put(propertyName, child);
}
child.addPropertyChangeListener(listener);
}
---------------------------------------child.addPropertyChangeListener的addPropertyChangeListener方法如下:public synchronized void addPropertyChangeListener(
PropertyChangeListener listener) {
if (listener instanceof PropertyChangeListenerProxy) {
PropertyChangeListenerProxy proxy =
(PropertyChangeListenerProxy)listener;
// Call two argument add method.
addPropertyChangeListener(proxy.getPropertyName(),
(PropertyChangeListener)proxy.getListener());
} else {
if (listeners == null) {
listeners = new EventListenerList();
}
listeners.add(PropertyChangeListener.class, listener);
}
}
-------------------------------------
listeners.add的add方法如下:public synchronized void add(Class t, EventListener l) {
if (l==null) {
// In an ideal world, we would do an assertion here
// to help developers know they are probably doing
// something wrong
return;
}
if (!t.isInstance(l)) {
throw new IllegalArgumentException("Listener " + l +
" is not of type " + t);
}
if (listenerList == NULL_ARRAY) {
// if this is the first listener added,
// initialize the lists
listenerList = new Object[] { t, l };
} else {
// Otherwise copy the array and add the new listener
int i = listenerList.length;
Object[] tmp = new Object[i+2];
System.arraycopy(listenerList, 0, tmp, 0, i); tmp[i] = t;
tmp[i+1] = l; listenerList = tmp;
}
}
Collection allProjects = soapclient.getProjects();
Iterator i = allProjects.iterator();
while (i.hasNext())
{
String name = (String) i.next();
subscription = subscription + " projectName = '" + name + "' OR";
if (!name.matches(".*_instance.*"))
this.projects.add(name);
}
-----------------------
但接下来是哪里体现双击其中一个project,产生一个新的编辑框呢?
另外,febchen()说的“好像涉及到bean了,用于动态刷新swing”怎么看的?
--------------------------------------
public class Manager extends JPanel { static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction")/*#BundleType=List*/; String url = null, host = null;
int port;
String userName = null;
String userPassword = null;
Collection projects = new ArrayList();
JProjectList projectList = null;
final JFrame p = new JFrame();
BonitaClient soapclient;
public final static String imageBase = "images/";
public final static ImageIcon icon = new ImageIcon(Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png")); public Manager(String userName, String userPassword) throws Exception { this.userName = userName;
this.userPassword = userPassword;
// Obtains bonita host and port
url = System.getProperty("bonita.host"); host = url.substring(7);
int point = host.indexOf(":");
url = host;
this.host = host.substring(0,point);
int portPoint = url.indexOf("/");
if (portPoint != -1)
this.port = new Integer(url.substring(point+1,portPoint)).intValue(); // ant application
else
this.port = new Integer(url.substring(point+1)).intValue(); //Java Web Start application BonitaClient soapclient = new BonitaClient(host, port, "/bonita_ws/services/");
soapclient.login(userName, userPassword);
this.soapclient = soapclient;
buildView();
} public void buildView() throws Exception {
String subscription = "(event = 'addUserProject' AND userName = '" + this.userName + "')" + " OR"; Collection allProjects = soapclient.getProjects();
Iterator i = allProjects.iterator();
while (i.hasNext())
{
String name = (String) i.next();
subscription = subscription + " projectName = '" + name + "' OR";
if (!name.matches(".*_instance.*"))
this.projects.add(name);
} MListener ml = MListener.getInstance(this.userName, this.userPassword, this.host, this.port);
ml.subscription(subscription.substring(0, subscription.length() - 3));
projectList = new JProjectList(this.soapclient, ml, this.projects);
projectList.setBackground(new Color(177,177,251));
JTodoList todoList = new JTodoList(this.soapclient, ml);
todoList.setBackground(new Color(177,177,251));
JActivityList activityList = new JActivityList(this.soapclient, ml);
activityList.setBackground(new Color(177,177,251)); projectList.addPropertyChangeListener(JProjectList.SELECTED, todoList);
projectList.addPropertyChangeListener(JProjectList.SELECTED, activityList); java.net.URL iconUrl = Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png");
p.setIconImage(Toolkit.getDefaultToolkit().getImage(iconUrl)); hero.client.manager.Menubar menubar = new hero.client.manager.Menubar(this);
menubar.setBackground(new Color(153, 153, 255));
p.setJMenuBar(menubar);
Container c = p.getContentPane();
c.setLayout(new GridLayout(3, 1));
c.add(projectList);
c.add(todoList);
c.add(activityList); p.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
try {
JMSServicesClient jms = JMSServicesClient.getInstance();
jms.closeConnection();
System.exit(0);
} catch (Exception ex) {
}
}
}); p.setSize(new Dimension(150, 400)); p.setTitle(resource.getString("manager.activity") + userName);
p.pack();
p.show();
}
JPanel jp = new JPanel(); Object[] possibleValues = this.projects.toArray();
JComboBox projectNames = new JComboBox(possibleValues);
jp.setLayout(new GridLayout(0, 2));
jp.add(new JLabel(resource.getString("manager.choose"), SwingConstants.LEFT));
jp.add(projectNames); JTextField newProject = new JTextField("", 0);
jp.setLayout(new GridLayout(0, 2));
jp.add(new JLabel(resource.getString("manager.create.name2"), SwingConstants.LEFT));
jp.add(newProject); int cloneOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.clone"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
if (cloneOption != JOptionPane.CANCEL_OPTION) {
while ((newProject.getText()).equals("") && cloneOption != JOptionPane.CANCEL_OPTION) {
JOptionPane.showMessageDialog(null,resource.getString("manager.create.name"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon);
cloneOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.clone"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
}
if (cloneOption != JOptionPane.CANCEL_OPTION) {
try {
if (exists(newProject.getText())) {
JOptionPane.showMessageDialog(null,resource.getString("manager.create.exist"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon);
} else{
soapclient.cloneProject((String) projectNames.getSelectedItem(), newProject.getText());
this.projects.clear();
Collection allProjects = soapclient.getProjects();
Iterator i = allProjects.iterator();
while (i.hasNext())
{
String name = (String) i.next();
if (!name.matches(".*_instance.*"))
this.projects.add(name);
}
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null,resource.getString("manager.create.exist"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon);
}
}
}
}
public void InstantiateProject() {
JPanel jp = new JPanel(); Object[] possibleValues = this.projects.toArray();
JComboBox projectNames = new JComboBox(possibleValues);
jp.setLayout(new GridLayout(0, 2));
jp.add(new JLabel(resource.getString("manager.choose"), SwingConstants.LEFT));
jp.add(projectNames); int instOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.inst"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
if (instOption != JOptionPane.CANCEL_OPTION) {
try {
soapclient.instantiateProject((String) projectNames.getSelectedItem());
this.projects.clear();
Collection allProjects = soapclient.getProjects();
Iterator i = allProjects.iterator();
while (i.hasNext())
{
String name = (String) i.next();
if (!name.matches(".*_instance.*"))
this.projects.add(name);
}
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(null,resource.getString("manager.inst.error")+", "+e.getMessage(),resource.getString("manager.create.inst"),JOptionPane.INFORMATION_MESSAGE,icon);
}
}
} private boolean exists(String project) {
try {
Object[] elems = this.projects.toArray();
for (int i = 0; i < elems.length; i++) {
if (((String) elems[i]).equalsIgnoreCase(project))
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
}
return true;
} public void NewProject() {
projectList.newProject();
}
static public void main(String[] args) {
boolean exit = false;
String userName = null;
String userPassword = null; if (System.getProperty("user.login") != null && System.getProperty("user.password") != null) {
try {
userName = System.getProperty("user.login");
char[] password = System.getProperty("user.password").toCharArray();
userPassword = new String(password);
new Manager(userName, userPassword);
} catch (Exception e) {
JOptionPane.showMessageDialog(null,resource.getString("manager.login.failed"),resource.getString("manager.login.login"),JOptionPane.INFORMATION_MESSAGE,icon);
System.exit(0);
}
} else {
while (!exit) {
JPanel jp = new JPanel(); JTextField login = new JTextField("", 0);
jp.setLayout(new GridLayout(0, 2));
jp.add(new JLabel(resource.getString("manager.login.login"), SwingConstants.LEFT));
jp.add(login); JPasswordField passwd = new JPasswordField("", 0);
jp.setLayout(new GridLayout(0, 2));
jp.add(new JLabel(resource.getString("manager.login.password"), SwingConstants.LEFT));
jp.add(passwd); try {
if (System.getProperty("user.login") != null && System.getProperty("user.password") != null) {
userName = System.getProperty("user.login");
char[] password = System.getProperty("user.password").toCharArray();
userPassword = new String(password);
new Manager(userName, userPassword);
exit = true;
} else { int option = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.login"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,icon);
if (option != JOptionPane.CANCEL_OPTION) {
while (((login.getText()).equals("") || (passwd.getPassword()).length == 0) && option != JOptionPane.CANCEL_OPTION) {
JOptionPane.showMessageDialog(null,null,resource.getString("manager.login.relogin"),JOptionPane.QUESTION_MESSAGE,icon);
option = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.login"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon);
}
if (option != JOptionPane.CANCEL_OPTION) {
userName = (String) login.getText();
char[] password = passwd.getPassword();
userPassword = new String(password);
new Manager(userName, userPassword);
exit = true;
} else
System.exit(0);
} else
System.exit(0);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null,resource.getString("manager.login.failed"),resource.getString("manager.login.login"),JOptionPane.QUESTION_MESSAGE,icon);
exit = false;
}
}
}
}
}
---------------------------------
哪位帮我指一下是哪里执行“双击”动作呢???bow!!!
---------------------------------
public void mouseReleased(MouseEvent e) {
try {
if (!tree.isSelectionEmpty()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON3_MASK)
!= 0) {
JPopupMenu menu = new JPopupMenu();
PopupMenu(menu); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension size = menu.getPreferredSize(); // Flip along screen int x = e.getX();
int y = e.getY(); menu.show(this,e.getX() - (int) jsppl.getViewport().getViewPosition().getX(),e.getY()- (int) jsppl.getViewport().getViewPosition().getY());
} else if (e.getClickCount() == 1 && !node.isRoot()) {
String pl = node.getUserObject().toString();
firePropertyChange(SELECTED, "", pl);
} else if (e.getClickCount() == 2 && !node.isRoot()) {
try {
if (!projects.containsKey(node.getUserObject().toString())) {
frame = new hero.client.grapheditor.Frame(node.getUserObject().toString(),soapclient, false);
frame.setSize(new Dimension(500, 400));
frame.setVisible(true);
projects.put(node.getUserObject().toString(),frame);
frame.addPropertyChangeListener(PROJECTCLOSE, this);
} else {
frame =(hero.client.grapheditor.Frame) projects.get(node.getUserObject().toString());
frame.requestFocus();
}
} catch (Exception ce) {
//JOptionPane.showMessageDialog(null,resource.getString("jprojectlist.modify")+ node.getUserObject().toString()+ resource.getString("jprojectlist.proj"),resource.getString("jprojectlist.open"),JOptionPane.INFORMATION_MESSAGE,icon);
}
}
}
} catch (Exception e1){
JOptionPane.showMessageDialog(null,resource.getString("jprojectlist.error"),resource.getString("jprojectlist.interror"),JOptionPane.INFORMATION_MESSAGE,icon);
}
}
-----------------------------
是不是这个方法体现的?!但,当发生双击projectList里的某个project时,是哪条语句调用了这个方法呢???
e.getClickCount() == 2这个代表双击,同时有不是根节点,产生一个新的frameif (e.getClickCount() == 2 && !node.isRoot()) {
try {
if (!projects.containsKey(node.getUserObject().toString())) {
frame = new hero.client.grapheditor.Frame(node.getUserObject().toString(),soapclient, false);
frame.setSize(new Dimension(500, 400));
frame.setVisible(true);
projects.put(node.getUserObject().toString(),frame);
frame.addPropertyChangeListener(PROJECTCLOSE, this);
}
还是得好好补补swing的基础知识,除了sun的swing的tutorial,有没有哪本关于swing的比较新又比较好的书?!