现有以下代码,要求添加一个水品和垂直的滚动条,请高手指点,非常感谢

首先是GUI类主要实现界面的搭建,要求是在此代码中添加代码实现水平和垂直滚动条的添加和鼠标键盘的监听和操作
package npu.wsn.fan.SULS;

import java.awt.Scrollbar;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.border.LineBorder;
import javax.swing.tree.DefaultMutableTreeNode;

import npu.wsn.fan.SULS.ScreenCapture;
import npu.wsn.fan.SULS.DataBase;

/**
 * @author Fan.xx
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class GUI extends JFrame implements UpdateControl {
   
    public GUI(MutiNodes mNodeValue){
       
        this.mNode = mNodeValue;
       
        self = this;
        saveFileDialog = new JFileChooser(this.getClass().getResource("/").toString().substring(6));
       
        runt = Runtime.getRuntime();
       
       
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        setResizable(false);
        setJMenuBar(menuBar);
        setTitle("SULS 1.0");
        setLocation(250,50);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        store = new JButton("Store");
        store.setMnemonic('S');
        store.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {
                cal   =   Calendar.getInstance();
                d = cal.getTime();
               
                String name = null;
                int i =0;
                try{
                    database.InitData();
                    while(i < mNode.getNameList().size()){
                        name = (String)mNode.getNameList().get(i);                     
                        database.StoreData(mNode.getNode(name),d.toLocaleString());
                        i++;
                    }
                }catch(Exception ea){
                     ea.printStackTrace();
                }
               
                ScreenCapture scp = new ScreenCapture(getX()+182,getY()+55,756,607);
                paint();
                scp.captureScreen();
               
                try {
                    String command = "re.exe";
                    Process process = runt.exec(command);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
             }
            });
   
        update = new JButton("Update");
        update.setMnemonic('U');
        update.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {
                paint();
                nodeTree = new JTree(GetTreeNode.getTree(mNode));
                nodeTree.expandRow(1);
                nodeTreePane.getViewport().add(nodeTree);
            }
        });

        //  menuItem init
     
        saveDataItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                int val = saveFileDialog.showSaveDialog(self);
                File f = saveFileDialog.getSelectedFile();
                if(f!= null){
                    try {
                        OutputStream os = new FileOutputStream(f);
                        os.write(text.getText().getBytes());
                    } catch (IOException e1) {
                        // TODO 自动生成 catch 块
                        e1.printStackTrace();
                    }              
                }
            }
        });
       
        saveImgItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                int val = saveFileDialog.showSaveDialog(self);
                File f = saveFileDialog.getSelectedFile();
                if(f!= null){
                    ScreenCapture scp = new ScreenCapture(getX()+182,getY()+55,756,607); 
                    paint(); 
                    scp.captureScreen(f);
                }       
            }        
        });
     
        exitItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_X,InputEvent.CTRL_MASK));
        exitItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                if(optionPane.showConfirmDialog(self,"Sure to quit ?","Confirmation",JOptionPane.WARNING_MESSAGE)==0){
                    System.exit(0);
                }
            }
        });
       
        setMenuItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_P,InputEvent.CTRL_MASK));
        setMenuItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                String comm = optionPane.showInputDialog(self , "Set coordinate of node ( Named: new1 Coordinate:0,0,0 )./n" +
                                  "e.g. P PC new1 0 0 0","Setting",JOptionPane.QUESTION_MESSAGE);
                if(comm != null){
                    try {
                        serialOut.write(new String(comm+"/r/n").getBytes());
                        paint();
                    } catch (IOException e1) {
                        // TODO 自动生成 catch 块
                        e1.printStackTrace();
                    }
                }
            }
        });
       
        getDataItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_D,InputEvent.CTRL_MASK));;
        getDataItem.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {
                // TODO 自动生成方法存根
               
                isGetData = !isGetData;
               
            }});
       
        helpItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                try {
                    String dir = this.getClass().getResource("/").toString().substring(6);
                    Process process = runt.exec("notepad "+dir+"readme.txt");
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }    
        });
       
        aboutItem.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                optionPane.showMessageDialog(self , "Self-Update Localization System/n" +
                  "Edition:1.0/n" +
                  "(c) 2008 Northwestern Polytechnical University WSN Lab","About",JOptionPane.INFORMATION_MESSAGE);
                self.repaint();
            }
        });
       
        zoomInItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_I,InputEvent.CTRL_MASK));;
        zoomInItem.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {
                // TODO 自动生成方法存根                       
                zoom +=0.5;
                if(zoom>2.0)
                    zoom=2.0;
            }
           
        });
       
        zoomOutItem.setAccelerator(KeyStroke.getKeyStroke (KeyEvent.VK_O,InputEvent.CTRL_MASK));;
        zoomOutItem.addActionListener(new ActionListener(){

            public void actionPerformed(ActionEvent e) {
                // TODO 自动生成方法存根
                zoom -=0.5;
                if(zoom <1.0)
                    zoom=1.0;
            }
           
        });
       
        setMenuItem.setBackground(Color.WHITE);
        getDataItem.setBackground(Color.WHITE);
        startMenu.add(setMenuItem);
        startMenu.addSeparator();
        startMenu.add(getDataItem);
        startMenu.setMnemonic('T');
       

        saveDataItem.setBackground(Color.WHITE);
        saveImgItem.setBackground(Color.WHITE);
        exitItem.setBackground(Color.WHITE);
        fileMenu.add(saveDataItem);
        fileMenu.add(saveImgItem);
        fileMenu.addSeparator();
        fileMenu.add(exitItem);
        fileMenu.setMnemonic('F');
       
        zoomInItem.setBackground(Color.WHITE);
        zoomOutItem.setBackground(Color.WHITE);
        viewMenu.add(zoomInItem);
        viewMenu.add(zoomOutItem);
        viewMenu.setMnemonic('V');
       
        helpItem.setBackground(Color.WHITE);
        aboutItem.setBackground(Color.WHITE);
        helpMenu.add(helpItem);
        helpMenu.addSeparator();
        helpMenu.add(aboutItem);
        helpMenu.setMnemonic('H');
       
        menuBar.add(fileMenu);
        menuBar.add(startMenu);
        menuBar.add(viewMenu);
        menuBar.add(helpMenu);
       
        text = new JTextArea("---------------------------------------------------------------------------------/n" +
                " Welcome to SULS !                                                      /n" +
                " Please check the nodes first and search the detail here .      /n" +
                "--------------------------------------------------------------------------------/n", 6, 68);
        text.setBackground(Color.PINK);
        text.setEditable(false);   

        nodeTree = new JTree(GetTreeNode.getTree(mNode));
        nodeTreePane = new JScrollPane();
        nodeTreePane.getViewport().add(nodeTree);

        knownListener = new JTextField("",6);
        knownBeacon = new JTextField("",6);
        beacon = new JLabel("Beacon ");
        listener = new JLabel("Listener ");

        buttonPane = new JPanel();
        buttonPane.setLayout(new GridLayout(3,2,20,10));
        buttonPane.add(beacon);
        buttonPane.add(knownBeacon);
        buttonPane.add(listener);
        buttonPane.add(knownListener);
        buttonPane.add(update);
        buttonPane.add(store);
        buttonPane.setBackground(Color.LIGHT_GRAY);
       
        drawpane = new JPanel();
        drawpane.setSize(760,400);
        drawpane.setBackground(Color.WHITE);
        paneBack.setIcon(new ImageIcon("img.jpg"));
        //drawpane.add(paneBack);
        drawpane.setBorder(new LineBorder(Color.LIGHT_GRAY,5));
        pane = new JScrollPane(text);
        pane.setBorder(new LineBorder(Color.GRAY,2));
       
        infopane = new JPanel();
        infopane.setBackground(Color.LIGHT_GRAY);
        infopane.setBorder(new LineBorder(Color.GRAY,0));
        infopane.add(pane,BorderLayout.CENTER);
        infopane.add(buttonPane,BorderLayout.EAST);
       
      /*  scr=new Scrollbar();
        scr.setBounds(756, 607, 10, 100);
        scr.setBackground(null);
        scr.addMouseWheelListener(new MouseWheelListener)*/
       

        Container contentPanel = getContentPane();
        contentPanel.setBackground(Color.LIGHT_GRAY);
        contentPanel.add(nodeTreePane,BorderLayout.WEST);
        contentPanel.add(drawpane, BorderLayout.CENTER);
        contentPanel.add(infopane, BorderLayout.SOUTH);
       
        this.setVisible(true);
       
       
        //optionPane.showMessageDialog(self, "Please first change the default distance between beacons(2m)","Warning",JOptionPane.WARNING_MESSAGE);
        //paint();
    }
   
    /* (非 Javadoc)
     * @see npu.wsn.fan.SULS.UpdateControl#newMsg(npu.wsn.fan.SULS.SignNode)
     */
    public void newMsg(SignNode signNode) {
        // TODO 自动生成方法存根

        if(signNode.getMode().equalsIgnoreCase("L")){
            text.append("Node : ID="+signNode.getSpaceID()+" , MD="+signNode.getMode()
                    +" , CD=("+signNode.getX()+","
                    +signNode.getY()+","
                    +signNode.getZ()+")"+" , "
                    //+signNode.getData().toString()
                    +"/n");
            text.setCaretPosition(text.getText().length());
        }
       
        mNode.storeNode(signNode);
        /*if(mNode.storeNode(signNode)==0){          
            optionPane.showMessageDialog(self , "Here comes the new node!/n" +
                  "  " +signNode.getSpaceID()+"  at  "+
                  signNode.getX()+"  "+
                  signNode.getY()+"  ","New",JOptionPane.INFORMATION_MESSAGE);
        }*/
       
        paint();
       
    }
   
    private void paint(){
       
       
        int beaconNum = mNode.getModeNum("B");
        int listenerNum = mNode.getModeNum("L");
        double radius = 7;
       
        knownBeacon.setText(new Integer(beaconNum).toString());
        knownListener.setText(new Integer(listenerNum).toString());
       
        Graphics2D g = (Graphics2D) drawpane.getGraphics();
        Rectangle2D rect = new Rectangle2D.Double(5, 5, 750, 600);//rect为Rectangle.Double类的一个实例,5为左上角的坐标x,y;750,600为宽度和高度
        g.setPaint(Color.GRAY);//框的颜色
        g.draw(rect);//绘制一个rect图像
  
        Rectangle2D recttem = new Rectangle2D.Double(5, 5, 750, 600);
        g.setPaint(Color.WHITE);//背景的颜色
        g.fill(recttem);//注意fill和draw的区别,fill绘制一个填充的对象
  
  //draw the net of showArea
        g.setPaint(Color.GRAY);//线的颜色
        Line2D line = new Line2D.Double();
       
        for(int row = 0;row<605;){
            line.setLine(5,50+row,755,50+row);
            g.draw(line);
            row+=100;
        }
        for(int lin = 0;lin<755;){
  
            line.setLine(25+lin,5,25+lin,605);
            g.draw(line);
            lin+=100;
        } 
  
       
  //show the BeaconNode
       
        if(null != mNode){
            Ellipse2D circle = new Ellipse2D.Double();
            SignNode temp = null;
            String nn;
            int i =0;
            while(i < mNode.getNameList().size()){
           
                nn = (String)mNode.getNameList().get(i);
                temp = mNode.getNode(nn);
               
                if(temp.getMode().equalsIgnoreCase("B")){
                   
                    g.setPaint(Color.BLUE);
                }
                else{
                   
                    g.setPaint(Color.RED);
                }
                   //前两个为中心点坐标,后两个为角点坐标,由两者共同设置此形状
                circle.setFrameFromCenter(125+zoom*temp.getX(), 550-zoom*temp.getY(), 125+zoom*temp.getX()+ radius, 550-zoom*temp.getY()+ radius);
                   
                g.fill(circle);
               
                g.setPaint(Color.DARK_GRAY);
                    //drawString()显示出指定的SpaceID,也就是显示出节点的号
                g.drawString(temp.getSpaceID(),125+(int)(zoom*temp.getX()), 520-(int)(zoom*temp.getY()));
              
                if(isGetData){//布尔型
               
                    g.setPaint(Color.BLUE);
                   
                    g.drawString(temp.getData().toString(),125+(int)(zoom*temp.getX()), 540-(int)(zoom*temp.getY()));
     //绘制指定矩形的边框
                    g.drawRect(160+(int)(zoom*temp.getX()), 533-(int)(zoom*temp.getY()), 20, 5);
                   
                    int n = (temp.getData().getData()*20)/temp.getData().maxValue;
                   
                    g.setPaint(Color.BLUE);
                   
                    g.fillRect(160+(int)(zoom*temp.getX()), 533-(int)(zoom*temp.getY()), n, 5);
                   
                }
           
                i++;
      
            }
        }
    }
   
    public void setSerialOut(OutputStream serialOut) {
       
        this.serialOut = serialOut;
       
    }
   
    private MutiNodes mNode = null;
   
    private JTextArea text;
   
    private JTextField knownListener;
   
    private JTextField knownBeacon;
   
    private JLabel listener;
   
    private JLabel beacon;
   
    private JButton update;
   
    private JButton store;
   
    private JPanel buttonPane;
   
    private JPanel drawpane;
   
    private JPanel infopane;
   
    private JScrollPane pane;
   
    private JScrollPane nodeTreePane;
   
    private JFrame self;
   
    private JTree nodeTree;
   
    private JLabel paneBack = new JLabel();
   
    private JOptionPane optionPane = new JOptionPane();
   
    private JMenuBar menuBar = new JMenuBar();
   
    private JMenu fileMenu = new JMenu("File");
   
    private JMenu startMenu = new JMenu("Tools");
   
    private JMenu helpMenu = new JMenu("Help");
   
    private JMenu viewMenu = new JMenu("View");
   
    private JMenuItem setMenuItem = new JMenuItem("Setting",new ImageIcon("icon/set.png"));
   
    private JMenuItem getDataItem = new JMenuItem("Get Data",new ImageIcon("icon/get.png"));
   
    private JMenuItem saveDataItem = new JMenuItem("Save Data",new ImageIcon("icon/data.png"));
   
    private JMenuItem saveImgItem = new JMenuItem("Save Image",new ImageIcon("icon/image.png"));
   
    private JMenuItem exitItem = new JMenuItem("Exit",new ImageIcon("icon/exit.png"));
   
    private JMenuItem aboutItem = new JMenuItem("About",new ImageIcon("icon/about.png"));
   
    private JMenuItem helpItem = new JMenuItem("Help",new ImageIcon("icon/help.png"));
   
    private JMenuItem zoomInItem = new JMenuItem("Zoom In" , new ImageIcon("icon/zoomin.png"));
   
    private JMenuItem zoomOutItem = new JMenuItem("Zoom Out",new ImageIcon("icon/zoomout.png"));
   
    private JFileChooser saveFileDialog ;
   
    private Runtime runt  =null;
   
    private DataBase database = new DataBase();
   
    private Calendar   cal=null;
   
    private Date d = null;
   
    private OutputStream serialOut = null;
   
    private double zoom = 1.0;
   
    private boolean isGetData=false;
   
    public final int DEFAULT_WIDTH = 943;
   
    public final int DEFAULT_HEIGHT = 790;

}
其中引用的ScreenCapture类如下:

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;


public class ScreenCapture {
   
    public ScreenCapture(int x, int y, int width,int height){
        try{
            robot = new Robot();
        }catch(Exception e){
            e.printStackTrace();
        }
        rect = new Rectangle(x,y,width,height);
    }
   
    public void captureScreen(){
        BufferedImage bufImage = null;
        String fn = "E:/web/www/pc.jpg";   
        try{
            File f= new File(fn);
            bufImage = robot.createScreenCapture(rect);
            ImageIO.write(bufImage,"jpg",f);
      
        }catch(Exception e){
            e.toString();
        }
    }
   
    public void captureScreen(File fn){
        BufferedImage bufImage = null;
        try{
            bufImage = robot.createScreenCapture(rect);
            ImageIO.write(bufImage,"jpg",fn);
      
        }catch(Exception e){
            e.toString();
        }
       
    }
   
    private Robot robot;
    private Rectangle rect;
}
引用的database为数据库,请高手指点啊谢谢帮忙了

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值