⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java~231~

📁 这是本人刚刚得到的JBuilder9软件开发项目实践的源码
💻 JAVA~231~
📖 第 1 页 / 共 3 页
字号:
  void drawRectangleItem_actionPerformed(ActionEvent e) {
    lineType = 3;           //3 is corresponding to rectangle
  }
  //菜单项准备画椭圆
  void drawEllipseItem_actionPerformed(ActionEvent e) {
    lineType = 4;            //4 is corresponding to ellipse
  }
  //菜单项准备画填充圆
  void drawFillOvalItem_actionPerformed(ActionEvent e) {
    lineType = 5;             //5 is corresponding to fillOval
  }
  //菜单项准备画任意线段
  void drawRandomItem_actionPerformed(ActionEvent e) {
    lineType = 6;
  }
  //菜单项准备输出文字
  void writeTextItem_actionPerformed(ActionEvent e) {
    lineType = 7;
  }
  //初始化点p1和p2
  void jScrollPane1_mousePressed(MouseEvent e) {
    p1 = e.getPoint();
    p2 = p1;
  }
  //进行图形绘制
  void jScrollPane1_mouseDragged(MouseEvent e) {
    g = this.jScrollPane1.getGraphics();
    //lineType表示所绘制的图形类型:1表示绘制线段,2表示绘制圆,3表示绘制矩形
    //4表示绘制椭圆,5表示绘制填充圆,6表示绘制任意线段,7表示输出文字
    switch(lineType){
      case 1:
        //用背景颜色覆盖前面的直线
        g.setColor(this.getBackground());
        g.drawLine(p1.x,p1.y,p2.x,p2.y);
        //设置当前画图颜色并绘制线段
        g.setColor(colour);
        g.drawLine(p1.x,p1.y,e.getX(),e.getY());
        p2 = e.getPoint();
        break;
      case 2:
        g.setColor(this.getBackground());
        if(Math.abs(e.getX() - p1.x) > Math.abs(e.getY() - p1.y)){
            //用背景颜色覆盖前面的圆
          if(Math.abs(p2.x - p1.x) > Math.abs(p2.y - p1.y))
            g.drawOval(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.x-p1.x));
          else
            g.drawOval(p1.x,p1.y,Math.abs(p2.y-p1.y),Math.abs(p2.y-p1.y));
            //设置当前的画图颜色并绘制圆
          g.setColor(colour);
          g.drawOval(p1.x, p1.y, Math.abs(e.getX() - p1.x),Math.abs(e.getX() - p1.x));
        }
        else{
          ////用背景颜色覆盖前面的圆
          if(Math.abs(p2.x - p1.x) > Math.abs(p2.y - p1.y))
            g.drawOval(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.x-p1.x));
          else
            g.drawOval(p1.x,p1.y,Math.abs(p2.y-p1.y),Math.abs(p2.y-p1.y));
            //设置当前的画图颜色并绘制圆
          g.setColor(colour);
          g.drawOval(p1.x, p1.y, Math.abs(e.getY() - p1.y),Math.abs(e.getY() - p1.y));
        }
        p2 = e.getPoint();
        break;
      case 3:
        //用背景颜色覆盖前面的圆
        g.setColor(this.getBackground());
        g.drawRect(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
        //设置当前画图颜色并绘制矩形
        g.setColor(colour);
        g.drawRect(p1.x,p1.y,Math.abs(e.getX()-p1.x),Math.abs(e.getY()-p1.y));
        p2 = e.getPoint();
        break;
      case 4:
        //用背景颜色覆盖前面的椭圆
        g.setColor(this.getBackground());
        g.drawOval(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
        //设置当前画图颜色并绘制椭圆
        g.setColor(colour);
        g.drawOval(p1.x,p1.y,Math.abs(e.getX()-p1.x),Math.abs(e.getY()-p1.y));
        p2 = e.getPoint();
        break;
      case 5:
        //用背景颜色覆盖前面的填充圆
        g.setColor(this.getBackground());
        g.fillOval(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
        //设置当前画图颜色并绘制填充圆
        g.setColor(colour);
        g.fillOval(p1.x,p1.y,Math.abs(e.getX()-p1.x),Math.abs(e.getY()-p1.y));
        p2 = e.getPoint();
        break;
      case 6:
        //设置当前画图颜色并绘制任意线段
        g.setColor(colour);
        g.drawLine(p1.x,p1.y,e.getX(),e.getY());
        p1 = e.getPoint();
        break;
      case 7:
        //输出文字
        JOptionPane optionPane = new JOptionPane();
        String text = optionPane.showInputDialog((Component)e.getSource(),"输入文字:","Dialog for text input",JOptionPane.PLAIN_MESSAGE);
       if(text != null){
          g.drawString(text, e.getX(), e.getY());
        }
        break;
      default:
        break;
    }
  }
  //工具栏快捷键准备画线段
  void lineBtn_actionPerformed(ActionEvent e) {
    this.drawLineItem_actionPerformed(e);
  }
  //工具栏快捷键准备画圆
  void roundBtn_actionPerformed(ActionEvent e) {
    this.drawRoundItem_actionPerformed(e);
  }
  //工具栏快捷键准备画椭圆
  void ellipseBtn_actionPerformed(ActionEvent e) {
    this.drawEllipseItem_actionPerformed(e);
  }
  //工具栏快捷键准备画填充圆
  void fillRoundBtn_actionPerformed(ActionEvent e) {
    this.drawFillOvalItem_actionPerformed(e);
  }
  //工具栏快捷键准备画矩形
  void rectBtn_actionPerformed(ActionEvent e) {
    this.drawRectangleItem_actionPerformed(e);
  }
  //工具栏快捷键准备画任意线段
  void randomLineBtn_actionPerformed(ActionEvent e) {
    this.drawRandomItem_actionPerformed(e);
  }
  //工具栏快捷键准备输出文字
  void textWriteBtn_actionPerformed(ActionEvent e) {
    this.writeTextItem_actionPerformed(e);
  }
  //菜单项退出系统
  void exitSystemItem_actionPerformed(ActionEvent e) {
    System.exit(0);
  }
  //工具栏快捷键退出系统
  void exitBtn_actionPerformed(ActionEvent e) {
    this.exitSystemItem_actionPerformed(e);
  }
  //选择当前绘图颜色
  void colorBtn_actionPerformed(ActionEvent e) {
    JColorChooser colorChooser = new JColorChooser();
    colour = colorChooser.showDialog(this,"选择颜色",colorBtn.getForeground());
  }
  //点击鼠标后进行文字处理
  void jScrollPane1_mouseClicked(MouseEvent e) {
  /*  JOptionPane optionPane = new JOptionPane();
    String text = optionPane.showInputDialog((Component)e.getSource(),"输入文字:","Dialog for text input",JOptionPane.PLAIN_MESSAGE);
    if(lineType == 7 && text != null){
      g = this.jScrollPane1.getGraphics();
      g.drawString(text,e.getX(),e.getY());
    }*/
  }
  //创建新的绘图面板
  void newFileBtn_actionPerformed(ActionEvent e) {
    g = this.jScrollPane1.getGraphics();
    g.clearRect(0,0,this.jScrollPane1.getWidth(),this.jScrollPane1.getHeight());
    colour = new Color(122,122,122);
    g.setColor(colour);
    lineType = 0;
  }
  //******************************声音播放模块*****************************
  //选择声音文件
  void audioFileOpenItem_actionPerformed(ActionEvent e) {
    JFileChooser musicChooser = new JFileChooser();
    int returnVal = musicChooser.showOpenDialog(this);
    if(returnVal == JFileChooser.APPROVE_OPTION){
      try {
        musicURL = musicChooser.getSelectedFile().toURL();
      }
      catch (MalformedURLException ex) {}
    }
  }
  //开始播放音乐
  void playAudioItem_actionPerformed(ActionEvent e) {
    if(musicURL == null)
      return;
    music = Applet.newAudioClip(musicURL);
    music.loop();
  }
  //停止播放音乐
  void abortAudioItem_actionPerformed(ActionEvent e) {
    music.stop();
  }
  //*****************************动画制作模块*******************************
  //选择动画文件
  void openImageFileItem_actionPerformed(ActionEvent e) {
    JFileChooser imageChooser = new JFileChooser();
    int returnVal = imageChooser.showOpenDialog(this);
    if(returnVal == JFileChooser.APPROVE_OPTION){
      try {
        imageURL = imageChooser.getSelectedFile().toURL();
        imageName = imageChooser.getSelectedFile().getName();
      }
      catch (MalformedURLException ex) {}
    }
  }
  //m_demoType表示动画类型:1表示缩放平移动画,2表示不擦除平移动画,3表示淡入淡出动画
  //缩放平移动画,对应的动画类型值为1
  void zoomHerizonDemoItem_actionPerformed(ActionEvent e) {
    if(imageURL == null)
      return;
    g = this.jScrollPane1.getGraphics();
    ImageIcon icon = new ImageIcon(imageURL,imageName);
    //将图像装入内存
    image = icon.getImage();
    //创建当前动画线程前终止其他动画线程
    if(thread != null){
      thread.stop();
      thread = null;
    }
    int demoType = 1;
    thread = new DemoThread(image, this.jScrollPane1, demoType);
    thread.start();
  }
  //不擦除平移动画,对应的动画类型值为2
  void noEraseHerezonDemoItem_actionPerformed(ActionEvent e) {
    if(imageURL == null)
      return;
    g = this.jScrollPane1.getGraphics();
    ImageIcon icon = new ImageIcon(imageURL,imageName);
    //将图像装入内存
    image = icon.getImage();
    //创建当前动画线程前终止其他动画线程
    if(thread != null){
      thread.stop();
      thread = null;
    }
    int demoType = 2;
    thread = new DemoThread(image, this.jScrollPane1, demoType);
    thread.start();
  }
  //淡入淡出动画,对应的动画类型值为3
  void lightInOutDemoItem_actionPerformed(ActionEvent e) {
/*    if(imageURL == null)
      return;
    g = this.jScrollPane1.getGraphics();
    ImageIcon icon = new ImageIcon(imageURL,imageName);
    image = icon.getImage();
    //创建当前动画线程前终止其他动画线程
    if(thread != null){
      thread.stop();
      thread = null;
    }
    int demoType = 3;
    thread = new DemoThread(image, this.jScrollPane1, demoType);
    thread.start();  */
  }
  //终止动画线程
  void stopDemoItem_actionPerformed(ActionEvent e) {
    if(thread != null){
      thread.stop();
      thread = null;
      g = this.jScrollPane1.getGraphics();
      g.clearRect(0,0,this.jScrollPane1.getWidth(),
                  this.jScrollPane1.getHeight());
    }
  }
  //暂停播放动画
  void pauseDemoItem_actionPerformed(ActionEvent e) {
    if (thread != null)
      thread.suspend();
  }
  //继续播放动画
  void resumeDemoItem_actionPerformed(ActionEvent e) {
    if(thread != null)
      thread.resume();
  }

}

//*************************************系统自动生成代码****************************

class MainFrame_drawRoundItem_actionAdapter implements java.awt.event.ActionListener {
  MainFrame adaptee;

  MainFrame_drawRoundItem_actionAdapter(MainFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.drawRoundItem_actionPerformed(e);
  }
}

class MainFrame_drawRectangleItem_actionAdapter implements java.awt.event.ActionListener {
  MainFrame adaptee;

  MainFrame_drawRectangleItem_actionAdapter(MainFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.drawRectangleItem_actionPerformed(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -