当前位置: 代码迷 >> Java相关 >> [求助]JAVA小程序编写
  详细解决方案

[求助]JAVA小程序编写

热度:176   发布时间:2007-07-02 17:45:11.0
[求助]JAVA小程序编写

我们的课程设计啊。。。都不会。。哪位好心人帮帮忙!!超级感谢


简单的日期显示程序
要求程序中有一个树组件,该树根节点有12个子节点,分别表示一年的12个月份。这12个子节点又分别有若干个代表月份日期的子节点。程序中还有一个文本域。当用鼠标选中一个节点时,将被选中的节点名称及相关信息(比如某些节日说明等)显示在文本域中。


类似的一个程序

import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.event.*;
import javax.swing.event.*;


public class MainFrame extends JFrame{
JPanel cp=new JPanel();
JTree jtree;
DefaultMutableTreeNode root;
JSplitPane jspane1=new JSplitPane ();
JScrollPane jscrpane1=new JScrollPane();
JScrollPane jscrpane2=new JScrollPane();
JTextArea jta1=new JTextArea("tree selected:");

public JTree3(){
this.setSize(300,300);
this. setTitle("try to use tree");
cp=(JPanel)this.getContentPane();
cp.setLayout(new BorderLayout());

jspane1.setDividerSize(10);
jspane1.setOneTouchExpandable(true);
jspane1.setDividerLocation(150);

root=new DefaultMutableTreeNode("school");
createTree(root);


jtree=new JTree(root);
jscrpane1.getViewport().add(jtree);
jspane1.add(jscrpane1,JSplitPane.LEFT);

jscrpane2.getViewport().add(jta1);
jspane1.setRightComponent(jscrpane2);
cp. add(jspane1,BorderLayout.CENTER);

jtree.addTreeSelectionLietener(new TreeSelectionLietener(){
public void valueChanged(TreeSelectionEvent e){
DefaultMutableTreeNode node=new DefaultMutableTreeNode();
node=(DefaultMutableTreeNode)jtree.getLastSeltectedPathComponent();
if(node==null) return;
Object info=node.getUserObject();
if(node.isLeaf());
jta1.append(info.toString()+"is selected,it is a leaf"+"\n");
else
jta1.append(info.toString()+"is selected,it is not a leaf"+"\n");
}
});
}
public static void main(String[] args){
JTree3 JTree3=new JTree3();
JTree3.setVisible(true);
}

private void createTree(DefaultMutableTreeNode root){
DefaultMutableTreeNode classroom=null;
DefaultMutableTreeNode number=null;

classroom= new DefaultMutableTreeNode("classroom");
root.add(classroom);
for(int i=1;i<=8;i++){
number=new DefaultMutableTreeNode("no"+String.valueOf(i));

if(i==4)
for(int j=1;j<=5;j++)
number.add(new DefaultMutableTreeNode("seat"+String.valueOf(j)));
classroom.add(number);
}
}
protected void processWindowEvent(WindowEvent e){
if(e.getID()==WindowEvent.WINDOW_CLOSING)
System.exit(0);
}
}

搜索更多相关的解决方案: JAVA  编写  

----------------解决方案--------------------------------------------------------
呜``都没有人来啊。。。
----------------解决方案--------------------------------------------------------
嗯!你写这个就差不多吧!!
----------------解决方案--------------------------------------------------------
是差不多。。。可是他要求的我不会啊
----------------解决方案--------------------------------------------------------
  相关解决方案