لديّ سؤال .. أتمنى الاجابة بإسرع وقت ممكن ...
أعمل على برنامج في ال JBuilder4 ..هذا البرنامج يعمل على رسم بعض الاشكال الهندسية ..
مثلا المربع وغيرها ...وقد نجحنا في إظهار هذه النتيجة .. يجب على البرنامج أن يحتوي على أنيميشن
لقد حاولنا وبحثنا ..ولكن لم ننجح في ذلك ...
بالاضافة إلى أن ال ComboBox of Paints and Rendering لا يعملوا ..
مع ان ما في أخطاء في الكود !!!
مشكلة أخرى !!! تحملنا أرجوك ...
ما عارفيييييييييييييييييييين شو نسوي
نريدtransformation Composite(shear and refraction)
بحثنا في ال نت .. لكن تورطنا في ال Package ...
أرفقت كود البرنامج كامل .. أتمنى مساعدتي ...
package graphicinterface;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPopupMenu;
import javax.swing.JMenu;
import javax.swing.JFrame;
import java.io.*;
import java.awt.geom.*;
import java.lang.reflect.*;
import java.lang.NullPointerException;
import javax.swing.Action;
import java.lang.*;
import java.lang.Object;
import javax.swing.LookAndFeel;
import java.net.*;
import java.util.*;
import java.util.Map;
import java.awt.image.*;
import java.awt.Image.*;
import java.lang.Integer;
import java.awt.font.*;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import java.awt.BasicStroke.*;
import java.awt.Shape;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2005
* Company:
* @author
* @version 1.0
*/
public class Draw extends JFrame {
static int C,R;
static int n=16,m=16;
static int width,length;
//Panel1 panel=new Panel1();
// private ColorAction redAction;
//static ColorAction redAction;
/*Matrix M1 = new Matrix();
Matrix M2 = new Matrix(2, 1, 3, 1, 0, 4);
Matrix M3 =
new Matrix(0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f);*/
static boolean no2D=false;
protected double[] matrix;
static int Lnodes[][] = new int[100][9];
static Coord[] coord = new Coord[100];
static int a[]=new int[10];
static int b[]=new int [10];
static Point[] p = new Point[10];
static AffineTransform at=new AffineTransform();
static Shape shapes[]=new Shape[3];
static BufferedImage bi;
static boolean firstTime=true;
static int ne=0;
static int e1;
static int f;
static int X1;
static int u;
static int q;
static int Y1;
static int x1;
static int y1;
static int x2;
static int y2;
static int tx;
static int ty;
static int sx1;
static int sy1;
static int x,y;
static int z,k;
static int L,W;
static int SEL; // the selected element
static int i;
static int h=L/n,w=W/n;
static double Angle;
static String s="";
static String s1="";
static int h1;
static int w1;
static int h2;
static int w2;
static int xcoord,ycoord;
private JPanel contentPane;
private JMenuBar jMenuBar1 = new JMenuBar();
private JMenu jMenuFile = new JMenu();
private JMenuItem jMenuFileExit = new JMenuItem();
private JMenuItem jMenuFileOpen = new JMenuItem();
private JMenuItem jMenuFileSave = new JMenuItem();
private JMenu jMenuAnalysis = new JMenu();
private JToolBar jToolBar = new JToolBar();
private JButton openButton = new JButton();
private JButton saveButton = new JButton();
private ImageIcon image1;
private ImageIcon image2;
private ImageIcon image3;
private JPanel DrawPanel = new JPanel();
private JComboBox OperationC = new JComboBox();
private JLabel OperLabel = new JLabel();
private JButton ClearButton = new JButton();
private JTextField X = new JTextField();
private JTextField Y = new JTextField();
private JLabel XLeb = new JLabel();
private JLabel YLeb = new JLabel();
private JButton DrawButton = new JButton();
//ColorAction ca=new ColorAction();
JLabel lengthl = new JLabel();
JLabel widthl = new JLabel();
JTextField lengthF = new JTextField();
JTextField widthF = new JTextField();
JButton meshB = new JButton();
private JPopupMenu Properties = new JPopupMenu();
private JMenuItem pDisx = new JMenuItem();
private JMenuItem pDisy = new JMenuItem();
private JMenuItem pShx = new JMenuItem();
private JMenuItem pShy = new JMenuItem();
private JMenu colorMenu=new JMenu("Color");
private JMenuItem cRed = new JMenuItem();
private JMenuItem cBlue = new JMenuItem();
private JMenuItem cWhite = new JMenuItem();
private JMenuItem cGreen = new JMenuItem();
JLabel primLabel = new JLabel();
JLabel lineLabel = new JLabel();
JLabel paintLabel = new JLabel();
JLabel strokeLabel = new JLabel();
JComboBox PrimitiveComboBox = new JComboBox();
JComboBox LineComboBox = new JComboBox();
JComboBox PaintsComboBox = new JComboBox();
JComboBox RenderingComboBox = new JComboBox();
JButton redrawButton = new JButton();
/**Construct the frame*/
public Draw() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
matrix = new double[16];
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public Draw(Draw m){
matrix = new double[16];
System.arraycopy(m.matrix, 0, matrix, 0, 16);
}
/**Component initialization*/
private void jbInit() throws Exception {
image1 = new ImageIcon(graphicinterface.Draw.class.getResource("openFile.gif"));
image2 = new ImageIcon(graphicinterface.Draw.class.getResource("closeFile.gif"));
image3 = new ImageIcon(graphicinterface.Draw.class.getResource("help.gif"));
//setIconImage(Toolkit.getDefaultToolkit().createImage(Draw.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.getContentPane().setBackground(Color.pink);
this.setSize(new Dimension(900, 900));
this.setTitle("GUI");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileOpen.setText("open");
jMenuFileSave.setText("save");
cRed.setText("Red");
cBlue.setText("White");
cWhite.setText("Green");
cGreen.setText("Blue");
pDisx.setText("Displacement X");
pDisy.setText("Displacement Y");
pShx.setText("Sheer X");
pShy.setText("Sheer Y");
XLeb.setVisible(true);
YLeb.setVisible(true);
X.setVisible(true);
Y.setVisible(true);
lengthl.setFont(new java.awt.Font("Serif", 3, 15));
lengthl.setVisible(true);
lengthF.setVisible(true);
widthl.setFont(new java.awt.Font("Serif", 3, 15));
widthl.setVisible(true);
widthF.setVisible(true);
jMenuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileExit_actionPerformed(e);
}
});
jMenuFileOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileOpen_actionPerformed(e);
}
});
jMenuFileSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileSave_actionPerformed(e);
}
});
cRed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cRed_actionPerformed(e);
}
});
cWhite.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cWhite_actionPerformed(e);
}
});
cGreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cGreen_actionPerformed(e);
}
});
cBlue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cBlue_actionPerformed(e);
}
});
meshB.setBackground(Color.lightGray);
meshB.setFont(new java.awt.Font("Serif", 3, 14));
contentPane.setBackground(SystemColor.inactiveCaptionText);
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
saveButton_actionPerformed(e);
}
});
openButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
openButton_actionPerformed(e);
}
});
primLabel.setText("Primitive");
primLabel.setBounds(new Rectangle(688, 352, 77, 24));
lineLabel.setText("Lines");
lineLabel.setBounds(new Rectangle(691, 378, 67, 26));
paintLabel.setText("Paints");
paintLabel.setBounds(new Rectangle(690, 401, 51, 25));
strokeLabel.setText("Rendering");
strokeLabel.setBounds(new Rectangle(686, 449, 75, 25));
PrimitiveComboBox.setBounds(new Rectangle(778, 353, 100, 21));
LineComboBox.setBounds(new Rectangle(778, 379, 100, 20));
PaintsComboBox.setBounds(new Rectangle(776, 402, 101, 20));
RenderingComboBox.setBounds(new Rectangle(778, 450, 102, 19));
redrawButton.setText("Redraw");
redrawButton.setBounds(new Rectangle(758, 541, 101, 30));
redrawButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
redrawButton_actionPerformed(e);
}
});
Properties.add(pDisx);
Properties.add(pDisy);
Properties.add(pShx);
Properties.add(pShy);
colorMenu.add(cRed);
colorMenu.add(cWhite);
colorMenu.add(cGreen);
colorMenu.add(cBlue);
Properties.add(colorMenu );
openButton.setIcon(image1);
openButton.setBackground(SystemColor.inactiveCaptionText);
openButton.setToolTipText("Open File");
saveButton.setIcon(image2);
saveButton.setBackground(SystemColor.inactiveCaptionText);
saveButton.setToolTipText("Save File");
jToolBar.setBackground(SystemColor.inactiveCaptionText);
jToolBar.setBounds(new Rectangle(9, 1, 558, 31));
DrawPanel.setBackground(Color.black);
DrawPanel.setForeground(Color.white);
DrawPanel.setBounds(new Rectangle(5, 33, 680, 578));
DrawPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
DrawPanel_mouseClicked(e);
}
});
OperationC.setFont(new java.awt.Font("SansSerif", 3, 12));
OperationC.setBounds(new Rectangle(814, 127, 102, 25));
OperationC.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//OperationC_actionPerformed(e);
OperationC_actionPerformed(e);
}
});
OperLabel.setBounds(new Rectangle(702, 126, 106, 29));
OperLabel.setText("Transformation");
OperLabel.setFont(new java.awt.Font("Serif", 3, 14));
ClearButton.setText("Clear");
ClearButton.setFont(new java.awt.Font("Serif", 3, 12));
ClearButton.setBackground(Color.lightGray);
ClearButton.setBounds(new Rectangle(632, 617, 71, 30));
ClearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
ClearButton_actionPerformed(e);
}
});
X.setBounds(new Rectangle(813, 179, 105, 24));
Y.setBounds(new Rectangle(811, 219, 108, 25));
XLeb.setFont(new java.awt.Font("Serif", 3, 15));
XLeb.setText("Xcoord");
XLeb.setBounds(new Rectangle(750, 180, 56, 20));
YLeb.setBounds(new Rectangle(745, 218, 53, 27));
YLeb.setText("Ycoord");
YLeb.setFont(new java.awt.Font("Serif", 3, 15));
DrawButton.setText("Draw");
DrawButton.setFont(new java.awt.Font("Serif", 3, 14));
DrawButton.setBackground(Color.lightGray);
DrawButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
DrawButton_actionPerformed(e);
}
});
DrawButton.setBounds(new Rectangle(561, 618, 70, 30));
lengthl.setText("length");
lengthl.setBounds(new Rectangle(734, 270, 80, 24));
widthl.setText("width");
widthl.setBounds(new Rectangle(733, 305, 85, 21));
lengthF.setBounds(new Rectangle(808, 268, 108, 24));
widthF.setBounds(new Rectangle(807, 304, 109, 24));
meshB.setBounds(new Rectangle(707, 617, 69, 30));
meshB.setText("Mesh");
meshB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
meshB_actionPerformed(e);
}
});
Properties.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
Properties_mouseClicked(e);
}
});
jToolBar.add(openButton);
jToolBar.add(saveButton);
contentPane.add(DrawPanel, null);
contentPane.add(jToolBar, null);
contentPane.add(widthF);
contentPane.add(lengthF);
contentPane.add(Y, null);
contentPane.add(X, null);
contentPane.add(XLeb, null);
contentPane.add(OperationC, null);
contentPane.add(OperLabel, null);
contentPane.add(YLeb, null);
//contentPane.add(panel,null);
contentPane.add(lengthl);
contentPane.add(widthl);
contentPane.add(DrawButton, null);
contentPane.add(ClearButton, null);
contentPane.add(meshB);
contentPane.add(primLabel, null);
contentPane.add(PrimitiveComboBox, null);
contentPane.add(LineComboBox, null);
contentPane.add(PaintsComboBox, null);
contentPane.add(RenderingComboBox, null);
contentPane.add(strokeLabel, null);
contentPane.add(paintLabel, null);
contentPane.add(lineLabel, null);
contentPane.add(redrawButton, null);
jMenuFile.add(jMenuFileExit);
jMenuFile.add(jMenuFileOpen);
jMenuFile.add(jMenuFileSave);
jMenuBar1.add(jMenuFile);
PrimitiveComboBox.addItem("rectangle");
PrimitiveComboBox.addItem("ellipse");
PrimitiveComboBox.addItem("text");
LineComboBox.addItem("thin");
LineComboBox.addItem("thick");
LineComboBox.addItem("chessboard");
LineComboBox.addItem("dashed");
PaintsComboBox.addItem("solid");
PaintsComboBox.addItem("gradient");
PaintsComboBox.addItem("polka");
RenderingComboBox.addItem("stroke");
RenderingComboBox.addItem("fill");
RenderingComboBox.addItem("stroke & fill");
this.setJMenuBar(jMenuBar1);
OperationC.addItem("Start");
OperationC.addItem("ShearX");
OperationC.addItem("ShearY");
OperationC.addItem("Scale");
OperationC.addItem("Translate");
OperationC.addItem("RefractionX");
OperationC.addItem("RefractionY");
for(int i =0;i<10;i++) p = new Point();
// shapes[0]=new Rectangle(100, 100, 100, 100);
// shapes[1]=new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
//shapes[2]=new TextLayout("Inta khal wa super full time", new Font("Bold", 10, 70), new FontRenderContext(null, false, false));
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**File | open action performed*/
public void jMenuFileOpen_actionPerformed(ActionEvent e) {
}
public void jMenuFileSave_actionPerformed(ActionEvent e) {
}
public void cRed_actionPerformed(ActionEvent e) {
drawCoord();
Graphics g = (Graphics) DrawPanel.getGraphics();
g.setColor(Color.red);
}
public void cWhite_actionPerformed(ActionEvent e) {
drawCoord();
Graphics g = (Graphics) DrawPanel.getGraphics();
g.setColor(Color.white);
}
public void cGreen_actionPerformed(ActionEvent e) {
drawCoord();
Graphics g = (Graphics) DrawPanel.getGraphics();
g.setColor(Color.green);
}
public void cBlue_actionPerformed(ActionEvent e) {
drawCoord();
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
g.setColor(Color.blue);
}
public void drawCoord(){
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
int xx = coord[Lnodes[SEL][1]].x;
int yy = coord[Lnodes[SEL][1]].y;
int wid=(coord[Lnodes[SEL][3]].x)-(coord[Lnodes[SEL][1]].x);
int hei=(coord[Lnodes[SEL][5]].y)-(coord[Lnodes[SEL][3]].y);
g.fillRect(xx,yy,wid,hei);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Draw_AboutBox dlg = new Draw_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
public void rectangle(){
Graphics2D g=(Graphics2D)DrawPanel.getGraphics();
xcoord = Integer.parseInt(X.getText());
ycoord = Integer.parseInt(Y.getText());
length = Integer.parseInt(lengthF.getText());
width = Integer.parseInt(widthF.getText());
g.setColor(Color.white);
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
}
Color swapColour(final Color current){
if(current.equals(Color.red)){
return Color.green;
}else{
return Color.red;
}
}
void ExitButton_actionPerformed(ActionEvent e) {
System.exit(0);
}
void ClearButton_actionPerformed(ActionEvent e) {
DrawPanel.repaint();
ne=0;
X.setText("");
Y.setText("");
lengthF.setText("");
widthF.setText("");
}
public void drawObject(){
Object primit = PrimitiveComboBox.getSelectedItem();
Object line = LineComboBox.getSelectedItem();
Object paint = PaintsComboBox.getSelectedItem();
//Object trans = TransformsComboBox.getSelectedItem();
Object render = RenderingComboBox.getSelectedItem();
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
// Sets the primit method.
if (primit.toString().equals("rectangle")) {
g.setColor(Color.white);
shapes[0] = new Rectangle(100, 100, 100, 100);
g.draw( shapes[0]);
}
if (primit.toString().equals("ellipse")) {
g.setColor(Color.white);
Ellipse2D e = new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
for(int i=0;i<10;i++){
e.setFrame(i*10,200-i*10,15*i,20*i);
g.draw(e);
}
return;
}
if (primit.toString().equals("text")) {
g.setColor(Color.red);
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Bold", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
//textAt.shear(0.11,(int)1);
//textAt.scale(20.0,(float)textTl.getBounds().getHeight());
shapes[2] = textTl.getOutline(textAt);
g.draw(shapes[2]);
g.fill(shapes[2]);
return;
}
// Sets the line method.
Stroke oldStroke = g.getStroke();
if (line.toString().equals("thin")) {
g.setColor(Color.white);
if (primit.toString().equals("rectangle")) {
shapes[0] = new Rectangle(100, 100, 100, 100);
g.setStroke(new BasicStroke(3.0f));
g.draw(shapes[0]);
}
if (primit.toString().equals("ellipse")) {
Ellipse2D e = new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
for(int i=0;i<10;i++)
e.setFrame(i*10,200-i*10,15*i,20*i);
g.setStroke(new BasicStroke(3.0f));
g.draw(e);
}
if (primit.toString().equals("text")) {
g.setColor(Color.red);
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Italic", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
shapes[2] = textTl.getOutline(textAt);
//g.draw(shapes[2]);
g.setStroke(new BasicStroke(3.0f));
g.draw(shapes[2]);
g.fill(shapes[2]);
}
return;
}
if (line.toString().equals("thick")) {
g.setColor(Color.white);
if (primit.toString().equals("rectangle")) {
shapes[0] = new Rectangle(100, 100, 100, 100);
BasicStroke s=new BasicStroke(10);
g.setStroke(s);
g.draw(shapes[0]);
}
if (primit.toString().equals("ellipse")) {
g.setColor(Color.white);
Ellipse2D e = new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
for(int i=0;i<10;i++)
e.setFrame(i*10,200-i*10,15*i,20*i);
BasicStroke s=new BasicStroke(10);
g.setStroke(s);
g.draw(e);
}
if (primit.toString().equals("text")) {
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Italic", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
shapes[2] = textTl.getOutline(textAt);
//g.draw(shapes[2]);
//g.fill(shapes[2]);
BasicStroke s=new BasicStroke(20);
g.setStroke(s);
g.draw(shapes[2]);
g.fill(shapes[2]);
}
return;
}
if (line.toString().equals("chessboard")) {
int squareSize=20;
Color colour=Color.red;
//shapes[0] = new Rectangle(100, 100, 100, 100);
//g.draw( shapes[0]);
for(int row=0;row<5;++row){
for(int column=0;column<5;++column){
g.setColor(colour);
g.fillRect(100+row*squareSize,100+column*squareSize,squareSize,squareSize);
if(column!=9){
colour=swapColour(colour);
}
}
}
}
if (line.toString().equals("dashed")) {
float dash[] = {10.0f};
g.setColor(Color.white);
if (primit.toString().equals("rectangle")) {
shapes[0] = new Rectangle(100, 100, 100, 100);
g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
g.draw(shapes[0]);
}
if (primit.toString().equals("ellipse")) {
shapes[1] =new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
g.draw(shapes[1]);
}
if (primit.toString().equals("text")) {
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Bold", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
shapes[2] = textTl.getOutline(textAt);
g.draw(shapes[2]);
g.fill(shapes[2]);
g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
g.draw(shapes[1]);
}
return;
}
// Sets the Paint method.
if (paint.toString().equals("solid")) {
Paint oldPaint = g.getPaint();
g.setPaint(Color.blue);
g.draw(shapes[0]);
return;
}
if (paint.toString().equals("gradient")) {
g.setPaint(new GradientPaint(0, 0, Color.orange, w-250, h, Color.blue, false));
return;
}
if (paint.toString().equals("polka")) {
BufferedImage buffi = new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
Graphics2D buffig = buffi.createGraphics();
buffig.setColor(Color.blue);
buffig.fillRect(0, 0, 15, 15);
buffig.setColor(Color.red);
buffig.translate((15/2)-(5/2), (15/2)-(5/2));
buffig.fillOval(0, 0, 7, 7);
Rectangle r = new Rectangle(0,0,25,25);
g.setPaint(new TexturePaint(buffi, r));
//g.draw(r);
return;
}
// Sets the rendering method.
if (render.toString().equals("stroke")) {
g.draw(shapes[0]); return;
}
if (render.toString().equals("fill")) {
g.setColor(Color.blue);
g.fill(shapes[0]);
return;
}
if (render.toString().equals("stroke & fill")) {
Graphics2D tempg2 = g;
g.fill(shapes[0]);
g.setColor(Color.darkGray);
g.draw(shapes[0]);
g.setPaint(tempg2.getPaint()); return;
}
}
void DrawButton_actionPerformed(ActionEvent e) {
rectangle();
Object obj = OperationC.getSelectedItem();
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
if (obj.toString().equals("ShearX")) {
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
g.setColor(Color.white);
g.shear(0.5,0.0);
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
//repaint();
}
if (obj.toString().equals("ShearY")) {
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
g.setColor(Color.white);
g.shear(0.0,0.5);
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
//panel.v=1;
// panel.repaint();
}
if (obj.toString().equals("RefractionX")){
reflectx();
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
}
}
public Draw reflectx(){
Draw tmp = new Draw();
tmp.matrix[(0<<2)+0] = -tmp.matrix[(0<<2)+0];
return mult(tmp);
}
public Draw mult(Draw m){
Draw tmp = new Draw(this);
for (int i=0;i<4;i++)
for (int j=0;j<4;j++) {
matrix[(i<<2)+j] = 0;
for (int k=0;k<4;k++)
matrix[(i<<2)+j] += tmp.matrix[(i<<2)+k] * m.matrix[(k<<2)+j];
}
return this;
}
public double[][] mult(double[][] a){
for (int i=0;i<a.length;i++)
mult(a[i]);
return a;
}
public double[] mult(double[] v){
double[] tmp = new double[4];
int i;
for (i=0;i<4;i++)
tmp[i] = v[i];
for (i=0;i<4;i++) {
v[i] = 0;
for (int j=0;j<4;j++)
v[i] += matrix[(i<<2)+j] * tmp[j];
}
return v;
}
public void mesh(){
//panel.v=2;
//panel.repaint();
Graphics2D r = (Graphics2D) DrawPanel.getGraphics();
x = Integer.parseInt(X.getText());
y= Integer.parseInt(Y.getText());
z = Integer.parseInt(lengthF.getText());
k = Integer.parseInt(widthF.getText());
r.setColor(Color.white);
JOptionPane nel = new JOptionPane("Columns");
n = Integer.parseInt(nel.showInputDialog("Enter N"));
m = Integer.parseInt(nel.showInputDialog("Enter M"));
w1=z/m;
h1=k/n;
BufferedWriter output = null;
try{
output = new BufferedWriter(new FileWriter("a:/mesh.txt"));
output.write(xcoord+" "+ycoord+" "+length+" "+width+ "\r\n");
for (int i=0;i<100;i++)coord[i] = new Coord();
for (int e1=1;e1<=n*m;e1++)
{
nen(e1,n,m);
coordinates(e1,n,m);
}
for (int e1=1;e1<=n*m;e1++)
{
output.write(e1 + "\r\n");
for(int i=1;i<=8;i++)
output.write(" "+Lnodes[e1][i]+" "+coord[Lnodes[e1][i]].getX()+ " " +coord[Lnodes[e1][i]].getY()+"\r\n");
}
output.flush();
}
catch(IOException ex){}
for( i=0;i<k;i=i+h1)r.drawLine((int)xcoord,(int)ycoord+i,(int)(xcoord+z),(int)ycoord+i);
for( i=0;i<z;i=i+w1)r.drawLine((int)xcoord+i,(int)ycoord,(int)(xcoord+i),(int)(ycoord+k));
for( i=1;i<=n;i++){
int x1 = x + h1/2+(i-1)*w1;
for(int f=1;f<=m;f++){
int y1 = y+h1/2+(f-1)*w1;
int r1 = (f-1)*n+i;
s="E"+r1;
r.setColor(Color.white);
r.drawString(s,x1,y1);
}
}
for ( int e1=1; e1<=n*m; e1++)
for (int i=1; i<=8; i++){
s1=""+Lnodes[e1][i];
r.setColor(Color.yellow);
r.setStroke(new BasicStroke(2.0f));
r.setColor(Color.yellow);
r.drawOval(coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y,1,1);
r.drawString( s1, coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y);
}
}
public void meshB_actionPerformed(ActionEvent e) {
mesh();
}
public static void main (final String[]args)throws IOException{
final Draw DrawPanel=new Draw();
System.exit(0);
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
DrawPanel.update(g);
if(args.length >0&& args[0].equals("-no2d")){
Draw.no2D=true;
}
}
private void elements(int e,int n,int m)throws IOException{
C=1; R= 1;
while((e-n)>0){
R= R+1;
e = e-n;
}// end while
C=e;
}// end elements
private void nen(int e,int n,int m)throws IOException{
elements(e,n,m);
Lnodes[e][1] = 3*R*n+2*(C+R) - 3*n -3;
Lnodes[e][2] = Lnodes[e][1]+1;
Lnodes[e][3]=Lnodes[e][1]+2;
Lnodes[e][4] =3*R*n+2*R+C-n;
Lnodes[e][5]= 3*R*n+2*(R+C)+1;
Lnodes[e][6] = Lnodes[e][5]-1;
Lnodes[e][7] =Lnodes[e][5]-2;
Lnodes[e][8] =Lnodes[e][4]-1;
}// end nen
private void coordinates(int e,int n, int m)throws IOException{
elements(e,n,m);
coord[Lnodes[e][1]].setX(xcoord+(C-1)*h1); coord[Lnodes[e][1]].setY(ycoord+(R-1)*w1);
coord[Lnodes[e][2]].setX(coord[Lnodes[e][1]].getX()+h1/2); coord[Lnodes[e][2]].setY(coord[Lnodes[e][1]].getY());
coord[Lnodes[e][3]].setX(xcoord+C*h1); coord[Lnodes[e][3]].setY(coord[Lnodes[e][1]].getY());
coord[Lnodes[e][4]].setX(coord[Lnodes[e][3]].getX()); coord[Lnodes[e][4]].setY(coord[Lnodes[e][3]].getY()+w1/2);
coord[Lnodes[e][5]].setX(coord[Lnodes[e][3]].getX()); coord[Lnodes[e][5]].setY(ycoord+R*w1);
coord[Lnodes[e][6]].setX(coord[Lnodes[e][2]].getX()); coord[Lnodes[e][6]].setY(coord[Lnodes[e][5]].getY());
coord[Lnodes[e][7]].setX(coord[Lnodes[e][1]].getX()); coord[Lnodes[e][7]].setY(coord[Lnodes[e][5]].getY());
coord[Lnodes[e][8]].setX(coord[Lnodes[e][1]].getX()); coord[Lnodes[e][8]].setY(coord[Lnodes[e][4]].getY());
}
void Properties_mouseClicked(MouseEvent e) {
}
void DrawPanel_mouseClicked(MouseEvent e1) {
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
if(e1.isMetaDown())
{
Properties.show(this,e1.getX(),e1.getY());
int x1 = e1.getX();
int y1 = e1.getY();
SEL = Search(x1,y1);
}
}
int Search(int x, int y){
int i;
for(i = 1;i<=m*n;i++){
if (x > coord[Lnodes[i][1]].x && x < coord[Lnodes[i][3]].x)
if (y > coord[Lnodes[i][1]].y && y< coord[Lnodes[i][7]].y)
break;
}
//Message.setText("i = "+i);
return(i);
}
void saveButton_actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(this,"Save shapes to file",FileDialog.SAVE);
fd.show();
String file = fd.getFile();
File ff=null;
BufferedWriter output = null;
try{
if (file != null) { // if user did not cancel file dialog
String dir = fd.getDirectory();
ff = new File(dir,file);
}//end if
output = new BufferedWriter(new FileWriter(ff));
output.write(xcoord+" "+ycoord+" "+length+" "+width+" "+n+" "+m+ "\r\n");
output.close();
} catch (IOException ext) {
System.out.println("error");
}
}//end saveButton
void jButton4_actionPerformed(ActionEvent e) {
//save();
}
void openButton_actionPerformed(ActionEvent e) {
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
FileDialog fd = new FileDialog(this,"Read shapes from file",FileDialog.LOAD);
fd.show();
String file = fd.getFile();
File ff=null;
try{
if (file != null){
String dir = fd.getDirectory();
ff = new File(dir,file);
}//end if
FileReader fr = new FileReader(ff);
BufferedReader br= new BufferedReader(fr);
String line = br.readLine();
while( line !=null){
StringTokenizer st=new StringTokenizer(line);
xcoord=Integer.parseInt(st.nextToken());
ycoord=Integer.parseInt(st.nextToken());
length=Integer.parseInt(st.nextToken());
width=Integer.parseInt(st.nextToken());
line=br.readLine();
g.setColor(Color.white);
rectangle();
n=Integer.parseInt(st.nextToken());
m=Integer.parseInt(st.nextToken());
g.setColor(Color.white);
w1=length/m;
h1=width/n;
for (int i=0;i<100;i++)coord[i] = new Coord();
for (int e1=1;e1<=n*m;e1++)
{
nen(e1,n,m);
coordinates(e1,n,m);
}
for( i=0;i<k;i=i+h1)g.drawLine((int)xcoord,(int)ycoord+i,(int)(xcoord+z),(int)ycoord+i);
for( i=0;i<z;i=i+w1)g.drawLine((int)xcoord+i,(int)ycoord,(int)(xcoord+i),(int)(ycoord+k));
for( i=1;i<=n;i++){
int x1 = x + h1/2+(i-1)*w1;
for(int f=1;f<=m;f++){
int y1 = y+h1/2+(f-1)*w1;
int r1 = (f-1)*n+i;
s="E"+r1;
g.setColor(Color.white);
g.drawString(s,x1,y1);
}
}
for ( int e1=1; e1<=n*m; e1++)
for (int i=1; i<=8; i++){
s1=""+Lnodes[e1][i];
g.setColor(Color.yellow);
g.setStroke(new BasicStroke(2.0f));
g.setColor(Color.yellow);
g.drawOval(coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y,1,1);
g.drawString( s1, coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y);
}
}//end while
line=br.readLine();
}//end try
catch(Exception ex){
ex.printStackTrace();
}//end catch
}// end openButton
void OperationC_actionPerformed(ActionEvent e) {
}
void redrawButton_actionPerformed(ActionEvent e) {
drawObject();
}
}//end class
حاولنا نعمل نسخة من ال سكرين شوت علشان نرسلها لك ... بس ما عرفنا
الطريقة .. إذا فيه طريقة علشان نرسلها لك .. نتمنى معرفتها ...
شكرا لك مسبقا ... وأتمنى الرد بسرعة |t
أعمل على برنامج في ال JBuilder4 ..هذا البرنامج يعمل على رسم بعض الاشكال الهندسية ..
مثلا المربع وغيرها ...وقد نجحنا في إظهار هذه النتيجة .. يجب على البرنامج أن يحتوي على أنيميشن
لقد حاولنا وبحثنا ..ولكن لم ننجح في ذلك ...
بالاضافة إلى أن ال ComboBox of Paints and Rendering لا يعملوا ..
مع ان ما في أخطاء في الكود !!!
مشكلة أخرى !!! تحملنا أرجوك ...
ما عارفيييييييييييييييييييين شو نسوي
نريدtransformation Composite(shear and refraction)
بحثنا في ال نت .. لكن تورطنا في ال Package ...
أرفقت كود البرنامج كامل .. أتمنى مساعدتي ...
package graphicinterface;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JPopupMenu;
import javax.swing.JMenu;
import javax.swing.JFrame;
import java.io.*;
import java.awt.geom.*;
import java.lang.reflect.*;
import java.lang.NullPointerException;
import javax.swing.Action;
import java.lang.*;
import java.lang.Object;
import javax.swing.LookAndFeel;
import java.net.*;
import java.util.*;
import java.util.Map;
import java.awt.image.*;
import java.awt.Image.*;
import java.lang.Integer;
import java.awt.font.*;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import java.awt.BasicStroke.*;
import java.awt.Shape;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2005
* Company:
* @author
* @version 1.0
*/
public class Draw extends JFrame {
static int C,R;
static int n=16,m=16;
static int width,length;
//Panel1 panel=new Panel1();
// private ColorAction redAction;
//static ColorAction redAction;
/*Matrix M1 = new Matrix();
Matrix M2 = new Matrix(2, 1, 3, 1, 0, 4);
Matrix M3 =
new Matrix(0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f);*/
static boolean no2D=false;
protected double[] matrix;
static int Lnodes[][] = new int[100][9];
static Coord[] coord = new Coord[100];
static int a[]=new int[10];
static int b[]=new int [10];
static Point[] p = new Point[10];
static AffineTransform at=new AffineTransform();
static Shape shapes[]=new Shape[3];
static BufferedImage bi;
static boolean firstTime=true;
static int ne=0;
static int e1;
static int f;
static int X1;
static int u;
static int q;
static int Y1;
static int x1;
static int y1;
static int x2;
static int y2;
static int tx;
static int ty;
static int sx1;
static int sy1;
static int x,y;
static int z,k;
static int L,W;
static int SEL; // the selected element
static int i;
static int h=L/n,w=W/n;
static double Angle;
static String s="";
static String s1="";
static int h1;
static int w1;
static int h2;
static int w2;
static int xcoord,ycoord;
private JPanel contentPane;
private JMenuBar jMenuBar1 = new JMenuBar();
private JMenu jMenuFile = new JMenu();
private JMenuItem jMenuFileExit = new JMenuItem();
private JMenuItem jMenuFileOpen = new JMenuItem();
private JMenuItem jMenuFileSave = new JMenuItem();
private JMenu jMenuAnalysis = new JMenu();
private JToolBar jToolBar = new JToolBar();
private JButton openButton = new JButton();
private JButton saveButton = new JButton();
private ImageIcon image1;
private ImageIcon image2;
private ImageIcon image3;
private JPanel DrawPanel = new JPanel();
private JComboBox OperationC = new JComboBox();
private JLabel OperLabel = new JLabel();
private JButton ClearButton = new JButton();
private JTextField X = new JTextField();
private JTextField Y = new JTextField();
private JLabel XLeb = new JLabel();
private JLabel YLeb = new JLabel();
private JButton DrawButton = new JButton();
//ColorAction ca=new ColorAction();
JLabel lengthl = new JLabel();
JLabel widthl = new JLabel();
JTextField lengthF = new JTextField();
JTextField widthF = new JTextField();
JButton meshB = new JButton();
private JPopupMenu Properties = new JPopupMenu();
private JMenuItem pDisx = new JMenuItem();
private JMenuItem pDisy = new JMenuItem();
private JMenuItem pShx = new JMenuItem();
private JMenuItem pShy = new JMenuItem();
private JMenu colorMenu=new JMenu("Color");
private JMenuItem cRed = new JMenuItem();
private JMenuItem cBlue = new JMenuItem();
private JMenuItem cWhite = new JMenuItem();
private JMenuItem cGreen = new JMenuItem();
JLabel primLabel = new JLabel();
JLabel lineLabel = new JLabel();
JLabel paintLabel = new JLabel();
JLabel strokeLabel = new JLabel();
JComboBox PrimitiveComboBox = new JComboBox();
JComboBox LineComboBox = new JComboBox();
JComboBox PaintsComboBox = new JComboBox();
JComboBox RenderingComboBox = new JComboBox();
JButton redrawButton = new JButton();
/**Construct the frame*/
public Draw() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
matrix = new double[16];
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public Draw(Draw m){
matrix = new double[16];
System.arraycopy(m.matrix, 0, matrix, 0, 16);
}
/**Component initialization*/
private void jbInit() throws Exception {
image1 = new ImageIcon(graphicinterface.Draw.class.getResource("openFile.gif"));
image2 = new ImageIcon(graphicinterface.Draw.class.getResource("closeFile.gif"));
image3 = new ImageIcon(graphicinterface.Draw.class.getResource("help.gif"));
//setIconImage(Toolkit.getDefaultToolkit().createImage(Draw.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.getContentPane().setBackground(Color.pink);
this.setSize(new Dimension(900, 900));
this.setTitle("GUI");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileOpen.setText("open");
jMenuFileSave.setText("save");
cRed.setText("Red");
cBlue.setText("White");
cWhite.setText("Green");
cGreen.setText("Blue");
pDisx.setText("Displacement X");
pDisy.setText("Displacement Y");
pShx.setText("Sheer X");
pShy.setText("Sheer Y");
XLeb.setVisible(true);
YLeb.setVisible(true);
X.setVisible(true);
Y.setVisible(true);
lengthl.setFont(new java.awt.Font("Serif", 3, 15));
lengthl.setVisible(true);
lengthF.setVisible(true);
widthl.setFont(new java.awt.Font("Serif", 3, 15));
widthl.setVisible(true);
widthF.setVisible(true);
jMenuFileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileExit_actionPerformed(e);
}
});
jMenuFileOpen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileOpen_actionPerformed(e);
}
});
jMenuFileSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuFileSave_actionPerformed(e);
}
});
cRed.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cRed_actionPerformed(e);
}
});
cWhite.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cWhite_actionPerformed(e);
}
});
cGreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cGreen_actionPerformed(e);
}
});
cBlue.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cBlue_actionPerformed(e);
}
});
meshB.setBackground(Color.lightGray);
meshB.setFont(new java.awt.Font("Serif", 3, 14));
contentPane.setBackground(SystemColor.inactiveCaptionText);
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
saveButton_actionPerformed(e);
}
});
openButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
openButton_actionPerformed(e);
}
});
primLabel.setText("Primitive");
primLabel.setBounds(new Rectangle(688, 352, 77, 24));
lineLabel.setText("Lines");
lineLabel.setBounds(new Rectangle(691, 378, 67, 26));
paintLabel.setText("Paints");
paintLabel.setBounds(new Rectangle(690, 401, 51, 25));
strokeLabel.setText("Rendering");
strokeLabel.setBounds(new Rectangle(686, 449, 75, 25));
PrimitiveComboBox.setBounds(new Rectangle(778, 353, 100, 21));
LineComboBox.setBounds(new Rectangle(778, 379, 100, 20));
PaintsComboBox.setBounds(new Rectangle(776, 402, 101, 20));
RenderingComboBox.setBounds(new Rectangle(778, 450, 102, 19));
redrawButton.setText("Redraw");
redrawButton.setBounds(new Rectangle(758, 541, 101, 30));
redrawButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
redrawButton_actionPerformed(e);
}
});
Properties.add(pDisx);
Properties.add(pDisy);
Properties.add(pShx);
Properties.add(pShy);
colorMenu.add(cRed);
colorMenu.add(cWhite);
colorMenu.add(cGreen);
colorMenu.add(cBlue);
Properties.add(colorMenu );
openButton.setIcon(image1);
openButton.setBackground(SystemColor.inactiveCaptionText);
openButton.setToolTipText("Open File");
saveButton.setIcon(image2);
saveButton.setBackground(SystemColor.inactiveCaptionText);
saveButton.setToolTipText("Save File");
jToolBar.setBackground(SystemColor.inactiveCaptionText);
jToolBar.setBounds(new Rectangle(9, 1, 558, 31));
DrawPanel.setBackground(Color.black);
DrawPanel.setForeground(Color.white);
DrawPanel.setBounds(new Rectangle(5, 33, 680, 578));
DrawPanel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
DrawPanel_mouseClicked(e);
}
});
OperationC.setFont(new java.awt.Font("SansSerif", 3, 12));
OperationC.setBounds(new Rectangle(814, 127, 102, 25));
OperationC.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//OperationC_actionPerformed(e);
OperationC_actionPerformed(e);
}
});
OperLabel.setBounds(new Rectangle(702, 126, 106, 29));
OperLabel.setText("Transformation");
OperLabel.setFont(new java.awt.Font("Serif", 3, 14));
ClearButton.setText("Clear");
ClearButton.setFont(new java.awt.Font("Serif", 3, 12));
ClearButton.setBackground(Color.lightGray);
ClearButton.setBounds(new Rectangle(632, 617, 71, 30));
ClearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
ClearButton_actionPerformed(e);
}
});
X.setBounds(new Rectangle(813, 179, 105, 24));
Y.setBounds(new Rectangle(811, 219, 108, 25));
XLeb.setFont(new java.awt.Font("Serif", 3, 15));
XLeb.setText("Xcoord");
XLeb.setBounds(new Rectangle(750, 180, 56, 20));
YLeb.setBounds(new Rectangle(745, 218, 53, 27));
YLeb.setText("Ycoord");
YLeb.setFont(new java.awt.Font("Serif", 3, 15));
DrawButton.setText("Draw");
DrawButton.setFont(new java.awt.Font("Serif", 3, 14));
DrawButton.setBackground(Color.lightGray);
DrawButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
DrawButton_actionPerformed(e);
}
});
DrawButton.setBounds(new Rectangle(561, 618, 70, 30));
lengthl.setText("length");
lengthl.setBounds(new Rectangle(734, 270, 80, 24));
widthl.setText("width");
widthl.setBounds(new Rectangle(733, 305, 85, 21));
lengthF.setBounds(new Rectangle(808, 268, 108, 24));
widthF.setBounds(new Rectangle(807, 304, 109, 24));
meshB.setBounds(new Rectangle(707, 617, 69, 30));
meshB.setText("Mesh");
meshB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
meshB_actionPerformed(e);
}
});
Properties.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
Properties_mouseClicked(e);
}
});
jToolBar.add(openButton);
jToolBar.add(saveButton);
contentPane.add(DrawPanel, null);
contentPane.add(jToolBar, null);
contentPane.add(widthF);
contentPane.add(lengthF);
contentPane.add(Y, null);
contentPane.add(X, null);
contentPane.add(XLeb, null);
contentPane.add(OperationC, null);
contentPane.add(OperLabel, null);
contentPane.add(YLeb, null);
//contentPane.add(panel,null);
contentPane.add(lengthl);
contentPane.add(widthl);
contentPane.add(DrawButton, null);
contentPane.add(ClearButton, null);
contentPane.add(meshB);
contentPane.add(primLabel, null);
contentPane.add(PrimitiveComboBox, null);
contentPane.add(LineComboBox, null);
contentPane.add(PaintsComboBox, null);
contentPane.add(RenderingComboBox, null);
contentPane.add(strokeLabel, null);
contentPane.add(paintLabel, null);
contentPane.add(lineLabel, null);
contentPane.add(redrawButton, null);
jMenuFile.add(jMenuFileExit);
jMenuFile.add(jMenuFileOpen);
jMenuFile.add(jMenuFileSave);
jMenuBar1.add(jMenuFile);
PrimitiveComboBox.addItem("rectangle");
PrimitiveComboBox.addItem("ellipse");
PrimitiveComboBox.addItem("text");
LineComboBox.addItem("thin");
LineComboBox.addItem("thick");
LineComboBox.addItem("chessboard");
LineComboBox.addItem("dashed");
PaintsComboBox.addItem("solid");
PaintsComboBox.addItem("gradient");
PaintsComboBox.addItem("polka");
RenderingComboBox.addItem("stroke");
RenderingComboBox.addItem("fill");
RenderingComboBox.addItem("stroke & fill");
this.setJMenuBar(jMenuBar1);
OperationC.addItem("Start");
OperationC.addItem("ShearX");
OperationC.addItem("ShearY");
OperationC.addItem("Scale");
OperationC.addItem("Translate");
OperationC.addItem("RefractionX");
OperationC.addItem("RefractionY");
for(int i =0;i<10;i++) p = new Point();
// shapes[0]=new Rectangle(100, 100, 100, 100);
// shapes[1]=new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
//shapes[2]=new TextLayout("Inta khal wa super full time", new Font("Bold", 10, 70), new FontRenderContext(null, false, false));
}
/**File | Exit action performed*/
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
/**File | open action performed*/
public void jMenuFileOpen_actionPerformed(ActionEvent e) {
}
public void jMenuFileSave_actionPerformed(ActionEvent e) {
}
public void cRed_actionPerformed(ActionEvent e) {
drawCoord();
Graphics g = (Graphics) DrawPanel.getGraphics();
g.setColor(Color.red);
}
public void cWhite_actionPerformed(ActionEvent e) {
drawCoord();
Graphics g = (Graphics) DrawPanel.getGraphics();
g.setColor(Color.white);
}
public void cGreen_actionPerformed(ActionEvent e) {
drawCoord();
Graphics g = (Graphics) DrawPanel.getGraphics();
g.setColor(Color.green);
}
public void cBlue_actionPerformed(ActionEvent e) {
drawCoord();
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
g.setColor(Color.blue);
}
public void drawCoord(){
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
int xx = coord[Lnodes[SEL][1]].x;
int yy = coord[Lnodes[SEL][1]].y;
int wid=(coord[Lnodes[SEL][3]].x)-(coord[Lnodes[SEL][1]].x);
int hei=(coord[Lnodes[SEL][5]].y)-(coord[Lnodes[SEL][3]].y);
g.fillRect(xx,yy,wid,hei);
}
/**Help | About action performed*/
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Draw_AboutBox dlg = new Draw_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
public void rectangle(){
Graphics2D g=(Graphics2D)DrawPanel.getGraphics();
xcoord = Integer.parseInt(X.getText());
ycoord = Integer.parseInt(Y.getText());
length = Integer.parseInt(lengthF.getText());
width = Integer.parseInt(widthF.getText());
g.setColor(Color.white);
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
}
Color swapColour(final Color current){
if(current.equals(Color.red)){
return Color.green;
}else{
return Color.red;
}
}
void ExitButton_actionPerformed(ActionEvent e) {
System.exit(0);
}
void ClearButton_actionPerformed(ActionEvent e) {
DrawPanel.repaint();
ne=0;
X.setText("");
Y.setText("");
lengthF.setText("");
widthF.setText("");
}
public void drawObject(){
Object primit = PrimitiveComboBox.getSelectedItem();
Object line = LineComboBox.getSelectedItem();
Object paint = PaintsComboBox.getSelectedItem();
//Object trans = TransformsComboBox.getSelectedItem();
Object render = RenderingComboBox.getSelectedItem();
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
// Sets the primit method.
if (primit.toString().equals("rectangle")) {
g.setColor(Color.white);
shapes[0] = new Rectangle(100, 100, 100, 100);
g.draw( shapes[0]);
}
if (primit.toString().equals("ellipse")) {
g.setColor(Color.white);
Ellipse2D e = new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
for(int i=0;i<10;i++){
e.setFrame(i*10,200-i*10,15*i,20*i);
g.draw(e);
}
return;
}
if (primit.toString().equals("text")) {
g.setColor(Color.red);
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Bold", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
//textAt.shear(0.11,(int)1);
//textAt.scale(20.0,(float)textTl.getBounds().getHeight());
shapes[2] = textTl.getOutline(textAt);
g.draw(shapes[2]);
g.fill(shapes[2]);
return;
}
// Sets the line method.
Stroke oldStroke = g.getStroke();
if (line.toString().equals("thin")) {
g.setColor(Color.white);
if (primit.toString().equals("rectangle")) {
shapes[0] = new Rectangle(100, 100, 100, 100);
g.setStroke(new BasicStroke(3.0f));
g.draw(shapes[0]);
}
if (primit.toString().equals("ellipse")) {
Ellipse2D e = new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
for(int i=0;i<10;i++)
e.setFrame(i*10,200-i*10,15*i,20*i);
g.setStroke(new BasicStroke(3.0f));
g.draw(e);
}
if (primit.toString().equals("text")) {
g.setColor(Color.red);
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Italic", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
shapes[2] = textTl.getOutline(textAt);
//g.draw(shapes[2]);
g.setStroke(new BasicStroke(3.0f));
g.draw(shapes[2]);
g.fill(shapes[2]);
}
return;
}
if (line.toString().equals("thick")) {
g.setColor(Color.white);
if (primit.toString().equals("rectangle")) {
shapes[0] = new Rectangle(100, 100, 100, 100);
BasicStroke s=new BasicStroke(10);
g.setStroke(s);
g.draw(shapes[0]);
}
if (primit.toString().equals("ellipse")) {
g.setColor(Color.white);
Ellipse2D e = new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
for(int i=0;i<10;i++)
e.setFrame(i*10,200-i*10,15*i,20*i);
BasicStroke s=new BasicStroke(10);
g.setStroke(s);
g.draw(e);
}
if (primit.toString().equals("text")) {
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Italic", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
shapes[2] = textTl.getOutline(textAt);
//g.draw(shapes[2]);
//g.fill(shapes[2]);
BasicStroke s=new BasicStroke(20);
g.setStroke(s);
g.draw(shapes[2]);
g.fill(shapes[2]);
}
return;
}
if (line.toString().equals("chessboard")) {
int squareSize=20;
Color colour=Color.red;
//shapes[0] = new Rectangle(100, 100, 100, 100);
//g.draw( shapes[0]);
for(int row=0;row<5;++row){
for(int column=0;column<5;++column){
g.setColor(colour);
g.fillRect(100+row*squareSize,100+column*squareSize,squareSize,squareSize);
if(column!=9){
colour=swapColour(colour);
}
}
}
}
if (line.toString().equals("dashed")) {
float dash[] = {10.0f};
g.setColor(Color.white);
if (primit.toString().equals("rectangle")) {
shapes[0] = new Rectangle(100, 100, 100, 100);
g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
g.draw(shapes[0]);
}
if (primit.toString().equals("ellipse")) {
shapes[1] =new Ellipse2D.Double(100.0, 100.0, 100.0, 100.0);
g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
g.draw(shapes[1]);
}
if (primit.toString().equals("text")) {
TextLayout textTl = new TextLayout("Inta khal wa super full time", new Font("Bold", 10, 70), new FontRenderContext(null, false, false));
AffineTransform textAt = new AffineTransform();
textAt.translate(100,100);
shapes[2] = textTl.getOutline(textAt);
g.draw(shapes[2]);
g.fill(shapes[2]);
g.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));
g.draw(shapes[1]);
}
return;
}
// Sets the Paint method.
if (paint.toString().equals("solid")) {
Paint oldPaint = g.getPaint();
g.setPaint(Color.blue);
g.draw(shapes[0]);
return;
}
if (paint.toString().equals("gradient")) {
g.setPaint(new GradientPaint(0, 0, Color.orange, w-250, h, Color.blue, false));
return;
}
if (paint.toString().equals("polka")) {
BufferedImage buffi = new BufferedImage(15, 15, BufferedImage.TYPE_INT_RGB);
Graphics2D buffig = buffi.createGraphics();
buffig.setColor(Color.blue);
buffig.fillRect(0, 0, 15, 15);
buffig.setColor(Color.red);
buffig.translate((15/2)-(5/2), (15/2)-(5/2));
buffig.fillOval(0, 0, 7, 7);
Rectangle r = new Rectangle(0,0,25,25);
g.setPaint(new TexturePaint(buffi, r));
//g.draw(r);
return;
}
// Sets the rendering method.
if (render.toString().equals("stroke")) {
g.draw(shapes[0]); return;
}
if (render.toString().equals("fill")) {
g.setColor(Color.blue);
g.fill(shapes[0]);
return;
}
if (render.toString().equals("stroke & fill")) {
Graphics2D tempg2 = g;
g.fill(shapes[0]);
g.setColor(Color.darkGray);
g.draw(shapes[0]);
g.setPaint(tempg2.getPaint()); return;
}
}
void DrawButton_actionPerformed(ActionEvent e) {
rectangle();
Object obj = OperationC.getSelectedItem();
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
if (obj.toString().equals("ShearX")) {
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
g.setColor(Color.white);
g.shear(0.5,0.0);
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
//repaint();
}
if (obj.toString().equals("ShearY")) {
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
g.setColor(Color.white);
g.shear(0.0,0.5);
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
//panel.v=1;
// panel.repaint();
}
if (obj.toString().equals("RefractionX")){
reflectx();
g.drawRect((int)xcoord,(int)ycoord,(int)length,(int)width);
}
}
public Draw reflectx(){
Draw tmp = new Draw();
tmp.matrix[(0<<2)+0] = -tmp.matrix[(0<<2)+0];
return mult(tmp);
}
public Draw mult(Draw m){
Draw tmp = new Draw(this);
for (int i=0;i<4;i++)
for (int j=0;j<4;j++) {
matrix[(i<<2)+j] = 0;
for (int k=0;k<4;k++)
matrix[(i<<2)+j] += tmp.matrix[(i<<2)+k] * m.matrix[(k<<2)+j];
}
return this;
}
public double[][] mult(double[][] a){
for (int i=0;i<a.length;i++)
mult(a[i]);
return a;
}
public double[] mult(double[] v){
double[] tmp = new double[4];
int i;
for (i=0;i<4;i++)
tmp[i] = v[i];
for (i=0;i<4;i++) {
v[i] = 0;
for (int j=0;j<4;j++)
v[i] += matrix[(i<<2)+j] * tmp[j];
}
return v;
}
public void mesh(){
//panel.v=2;
//panel.repaint();
Graphics2D r = (Graphics2D) DrawPanel.getGraphics();
x = Integer.parseInt(X.getText());
y= Integer.parseInt(Y.getText());
z = Integer.parseInt(lengthF.getText());
k = Integer.parseInt(widthF.getText());
r.setColor(Color.white);
JOptionPane nel = new JOptionPane("Columns");
n = Integer.parseInt(nel.showInputDialog("Enter N"));
m = Integer.parseInt(nel.showInputDialog("Enter M"));
w1=z/m;
h1=k/n;
BufferedWriter output = null;
try{
output = new BufferedWriter(new FileWriter("a:/mesh.txt"));
output.write(xcoord+" "+ycoord+" "+length+" "+width+ "\r\n");
for (int i=0;i<100;i++)coord[i] = new Coord();
for (int e1=1;e1<=n*m;e1++)
{
nen(e1,n,m);
coordinates(e1,n,m);
}
for (int e1=1;e1<=n*m;e1++)
{
output.write(e1 + "\r\n");
for(int i=1;i<=8;i++)
output.write(" "+Lnodes[e1][i]+" "+coord[Lnodes[e1][i]].getX()+ " " +coord[Lnodes[e1][i]].getY()+"\r\n");
}
output.flush();
}
catch(IOException ex){}
for( i=0;i<k;i=i+h1)r.drawLine((int)xcoord,(int)ycoord+i,(int)(xcoord+z),(int)ycoord+i);
for( i=0;i<z;i=i+w1)r.drawLine((int)xcoord+i,(int)ycoord,(int)(xcoord+i),(int)(ycoord+k));
for( i=1;i<=n;i++){
int x1 = x + h1/2+(i-1)*w1;
for(int f=1;f<=m;f++){
int y1 = y+h1/2+(f-1)*w1;
int r1 = (f-1)*n+i;
s="E"+r1;
r.setColor(Color.white);
r.drawString(s,x1,y1);
}
}
for ( int e1=1; e1<=n*m; e1++)
for (int i=1; i<=8; i++){
s1=""+Lnodes[e1][i];
r.setColor(Color.yellow);
r.setStroke(new BasicStroke(2.0f));
r.setColor(Color.yellow);
r.drawOval(coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y,1,1);
r.drawString( s1, coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y);
}
}
public void meshB_actionPerformed(ActionEvent e) {
mesh();
}
public static void main (final String[]args)throws IOException{
final Draw DrawPanel=new Draw();
System.exit(0);
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
DrawPanel.update(g);
if(args.length >0&& args[0].equals("-no2d")){
Draw.no2D=true;
}
}
private void elements(int e,int n,int m)throws IOException{
C=1; R= 1;
while((e-n)>0){
R= R+1;
e = e-n;
}// end while
C=e;
}// end elements
private void nen(int e,int n,int m)throws IOException{
elements(e,n,m);
Lnodes[e][1] = 3*R*n+2*(C+R) - 3*n -3;
Lnodes[e][2] = Lnodes[e][1]+1;
Lnodes[e][3]=Lnodes[e][1]+2;
Lnodes[e][4] =3*R*n+2*R+C-n;
Lnodes[e][5]= 3*R*n+2*(R+C)+1;
Lnodes[e][6] = Lnodes[e][5]-1;
Lnodes[e][7] =Lnodes[e][5]-2;
Lnodes[e][8] =Lnodes[e][4]-1;
}// end nen
private void coordinates(int e,int n, int m)throws IOException{
elements(e,n,m);
coord[Lnodes[e][1]].setX(xcoord+(C-1)*h1); coord[Lnodes[e][1]].setY(ycoord+(R-1)*w1);
coord[Lnodes[e][2]].setX(coord[Lnodes[e][1]].getX()+h1/2); coord[Lnodes[e][2]].setY(coord[Lnodes[e][1]].getY());
coord[Lnodes[e][3]].setX(xcoord+C*h1); coord[Lnodes[e][3]].setY(coord[Lnodes[e][1]].getY());
coord[Lnodes[e][4]].setX(coord[Lnodes[e][3]].getX()); coord[Lnodes[e][4]].setY(coord[Lnodes[e][3]].getY()+w1/2);
coord[Lnodes[e][5]].setX(coord[Lnodes[e][3]].getX()); coord[Lnodes[e][5]].setY(ycoord+R*w1);
coord[Lnodes[e][6]].setX(coord[Lnodes[e][2]].getX()); coord[Lnodes[e][6]].setY(coord[Lnodes[e][5]].getY());
coord[Lnodes[e][7]].setX(coord[Lnodes[e][1]].getX()); coord[Lnodes[e][7]].setY(coord[Lnodes[e][5]].getY());
coord[Lnodes[e][8]].setX(coord[Lnodes[e][1]].getX()); coord[Lnodes[e][8]].setY(coord[Lnodes[e][4]].getY());
}
void Properties_mouseClicked(MouseEvent e) {
}
void DrawPanel_mouseClicked(MouseEvent e1) {
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
if(e1.isMetaDown())
{
Properties.show(this,e1.getX(),e1.getY());
int x1 = e1.getX();
int y1 = e1.getY();
SEL = Search(x1,y1);
}
}
int Search(int x, int y){
int i;
for(i = 1;i<=m*n;i++){
if (x > coord[Lnodes[i][1]].x && x < coord[Lnodes[i][3]].x)
if (y > coord[Lnodes[i][1]].y && y< coord[Lnodes[i][7]].y)
break;
}
//Message.setText("i = "+i);
return(i);
}
void saveButton_actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(this,"Save shapes to file",FileDialog.SAVE);
fd.show();
String file = fd.getFile();
File ff=null;
BufferedWriter output = null;
try{
if (file != null) { // if user did not cancel file dialog
String dir = fd.getDirectory();
ff = new File(dir,file);
}//end if
output = new BufferedWriter(new FileWriter(ff));
output.write(xcoord+" "+ycoord+" "+length+" "+width+" "+n+" "+m+ "\r\n");
output.close();
} catch (IOException ext) {
System.out.println("error");
}
}//end saveButton
void jButton4_actionPerformed(ActionEvent e) {
//save();
}
void openButton_actionPerformed(ActionEvent e) {
Graphics2D g = (Graphics2D) DrawPanel.getGraphics();
FileDialog fd = new FileDialog(this,"Read shapes from file",FileDialog.LOAD);
fd.show();
String file = fd.getFile();
File ff=null;
try{
if (file != null){
String dir = fd.getDirectory();
ff = new File(dir,file);
}//end if
FileReader fr = new FileReader(ff);
BufferedReader br= new BufferedReader(fr);
String line = br.readLine();
while( line !=null){
StringTokenizer st=new StringTokenizer(line);
xcoord=Integer.parseInt(st.nextToken());
ycoord=Integer.parseInt(st.nextToken());
length=Integer.parseInt(st.nextToken());
width=Integer.parseInt(st.nextToken());
line=br.readLine();
g.setColor(Color.white);
rectangle();
n=Integer.parseInt(st.nextToken());
m=Integer.parseInt(st.nextToken());
g.setColor(Color.white);
w1=length/m;
h1=width/n;
for (int i=0;i<100;i++)coord[i] = new Coord();
for (int e1=1;e1<=n*m;e1++)
{
nen(e1,n,m);
coordinates(e1,n,m);
}
for( i=0;i<k;i=i+h1)g.drawLine((int)xcoord,(int)ycoord+i,(int)(xcoord+z),(int)ycoord+i);
for( i=0;i<z;i=i+w1)g.drawLine((int)xcoord+i,(int)ycoord,(int)(xcoord+i),(int)(ycoord+k));
for( i=1;i<=n;i++){
int x1 = x + h1/2+(i-1)*w1;
for(int f=1;f<=m;f++){
int y1 = y+h1/2+(f-1)*w1;
int r1 = (f-1)*n+i;
s="E"+r1;
g.setColor(Color.white);
g.drawString(s,x1,y1);
}
}
for ( int e1=1; e1<=n*m; e1++)
for (int i=1; i<=8; i++){
s1=""+Lnodes[e1][i];
g.setColor(Color.yellow);
g.setStroke(new BasicStroke(2.0f));
g.setColor(Color.yellow);
g.drawOval(coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y,1,1);
g.drawString( s1, coord[Lnodes [e1][i]].x,coord[Lnodes[e1][i]].y);
}
}//end while
line=br.readLine();
}//end try
catch(Exception ex){
ex.printStackTrace();
}//end catch
}// end openButton
void OperationC_actionPerformed(ActionEvent e) {
}
void redrawButton_actionPerformed(ActionEvent e) {
drawObject();
}
}//end class
حاولنا نعمل نسخة من ال سكرين شوت علشان نرسلها لك ... بس ما عرفنا
الطريقة .. إذا فيه طريقة علشان نرسلها لك .. نتمنى معرفتها ...
شكرا لك مسبقا ... وأتمنى الرد بسرعة |t