NetBeans 创建画图程序
来源:互联网 发布:vivo手机软件网络错误 编辑:程序博客网 时间:2024/05/23 21:26
在netBeans中并没有直接提供画图的JPanel,我们需要自定义一个类来重写paintComponent方法。
我们需要自定义一个类继承JPanel,并重写paintComponent方法
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package papp;import java.awt.Color;import java.awt.Graphics;import java.util.List;/** * * @author user */public class DrawPanel extends javax.swing.JPanel{ public DrawPanel() { initComponents(); } private void initComponents() { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); } public List<Pxy> pxyList; protected void paintComponent(Graphics g) { if(pxyList != null) { Color c = g.getColor(); for(int i=0;i<pxyList.size();i++) { Pxy pxy = pxyList.get(i); g.drawString(pxy.getId()+"", pxy.getX(), pxy.getY()); g.fillOval(pxy.getX(), pxy.getY(), 5, 5); g.setColor(c);; } } }}
上面就是一个将一系列的点画到面板上去的一个自定义的类
上面添加的一些其他方法,是copy JPanel模版的方法,要查看JPanel模版的代码。可以从 工具-》模版-》Swing GUI窗体-》JPanel窗体 选择下面的按钮,在编辑器打开
可以查看到模版代码:
<#assign licenseFirst = "/*"><#assign licensePrefix = " * "><#assign licenseLast = " */"><#include "../Licenses/license-${project.license}.txt"><#if package?? && package != "">package ${package};</#if>/** * * @author ${user} */public class ${name} extends javax.swing.JPanel { /** Creates new form ${name} */ public ${name}() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc=" Generated Code "> private void initComponents() { javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); } // </editor-fold> // Variables declaration - do not modify // End of variables declaration }
写好自定义的类之后,在工程中选中这个类,然后选择 工具-》添加到组件面板-》swing容器
然后切换到设计模式下,就可以看到组件面板多了一个自定义的面板,直接拖上去就可以做界面了,如果报错,就请参考模版的代码。
- NetBeans 创建画图程序
- netbeans中创建applet程序
- NetBeans 8.0 创建远程服务应该程序
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 使用NetBeans C/C++ Pack 5.5 创建程序(二)
- 2009-04-14技术学习:使用NetBeans创建Servlet程序
- 创建NetBeans模块项目
- NetBeans PHP 项目创建
- Netbeans创建JaveWeb项目
- netbeans开发gtk程序
- 我的画图程序
- MIDlet画图程序
- c# console 画图程序
- ADS1256芯片的驱动C程序
- PHP学习笔记——数组
- 提升Android应用视觉效果的10个UI技巧
- android 项目 R文件丢失时如何恢复?!
- .NET Reflector 7.6.1.824安装及破解(刚试了,绝对能用)
- NetBeans 创建画图程序
- c#的DateTime.Now函数详解
- 什么是makefile?(转贴整理)
- Group by字句的用法
- 有关UNICODE、ANSI字符集和相关字符串操作的总结
- 网络编程:TCP/IP网络协议的通俗理解
- 如何解决Word只能用安全模式打开
- bs_t结构及其相关函数的定义
- 中篇小说《南国梦》之陆游知己