主要是做一个画图板,单击工具栏的控件时,会弹出对话框,要求输入矩形(或圆、或椭圆)的height和width。主要框架都搭好了,界面也都做好了,却画不出图形,希望各位高手帮忙看看,谢谢!
代码如下(就贴了矩形的):
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.border.*;
import javax.swing.text.*;
class PadControl extends JFrame { //JFrame,生成主界面
private ObjectInputStream input;
private ObjectOutputStream output; //定义输入输出流,用来保存和调用图像
private DrawPanel drawingArea; //定义画图区域
drawings[] itemList=new drawings[5000]; //用来存放基本图形的数组
int index=0; //当前已经绘制的图形数目
private Color color=Color.black; //当前颜色为黑色
int R,G,B; //用来存放当前
int h,w; //用来存放JTextField传回的数值
public PadControl(){ //构造函数
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame=new JFrame("DrawPad"); //框架名为DrawPad
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置框架的关闭
JToolBar tbar=new JToolBar(); //新建工具栏
//在工具栏中加入矩形Button
JButton rect=new JButton("矩形");
rect.addActionListener( //注册监听
new ActionListener(){
public void actionPerformed(ActionEvent e) //触发则弹出对话框输入长、宽值
{
JDialog dialogRect=new JDialog(PadControl.this,"Draw Rect");
JDialog.setDefaultLookAndFeelDecorated(true);
dialogRect.setSize(280,200);
JLabel mhRect=new JLabel("Please input height(not 0!):");
dialogRect.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
final JTextField rheight=new JTextField("",10); //矩形的长
rheight.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
h=Integer.parseInt(rheight.getText().trim());
}
});
JLabel mwRect=new JLabel("Please input width(not 0!):");
final JTextField rwidth=new JTextField("",10); //矩形的宽
rwidth.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
代码如下(就贴了矩形的):
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.border.*;
import javax.swing.text.*;
class PadControl extends JFrame { //JFrame,生成主界面
private ObjectInputStream input;
private ObjectOutputStream output; //定义输入输出流,用来保存和调用图像
private DrawPanel drawingArea; //定义画图区域
drawings[] itemList=new drawings[5000]; //用来存放基本图形的数组
int index=0; //当前已经绘制的图形数目
private Color color=Color.black; //当前颜色为黑色
int R,G,B; //用来存放当前
int h,w; //用来存放JTextField传回的数值
public PadControl(){ //构造函数
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame=new JFrame("DrawPad"); //框架名为DrawPad
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置框架的关闭
JToolBar tbar=new JToolBar(); //新建工具栏
//在工具栏中加入矩形Button
JButton rect=new JButton("矩形");
rect.addActionListener( //注册监听
new ActionListener(){
public void actionPerformed(ActionEvent e) //触发则弹出对话框输入长、宽值
{
JDialog dialogRect=new JDialog(PadControl.this,"Draw Rect");
JDialog.setDefaultLookAndFeelDecorated(true);
dialogRect.setSize(280,200);
JLabel mhRect=new JLabel("Please input height(not 0!):");
dialogRect.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
final JTextField rheight=new JTextField("",10); //矩形的长
rheight.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
h=Integer.parseInt(rheight.getText().trim());
}
});
JLabel mwRect=new JLabel("Please input width(not 0!):");
final JTextField rwidth=new JTextField("",10); //矩形的宽
rwidth.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)