Advertisement
Shaun_B

Java paint package applet

Dec 12th, 2011
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 26.62 KB | None | 0 0
  1. import java.io.*;
  2. import java.applet.*;
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.lang.Math;
  6. // Phew! That works without any red lines, and now we need to give our package
  7. // a name, extent it to an Applet and implement both a Mouse Listener and a
  8. // Motion Listener too, as so:
  9. public class SketchPad extends Applet
  10. implements MouseListener, MouseMotionListener, ActionListener, KeyListener
  11. {
  12.     // Right, we're in to the program now. Let's declare some variables which
  13.     // we'll need to use later on.
  14.     // These first variables I tried to declare as booleans, but Java sux almost
  15.     // as much as Adobe ActionScript.
  16.     // What these do is give us conditions later on.
  17.     int Fill,Rect,Oval,RoundRect,Swirl,Str;
  18.     // The following variables set up some mathematics stuff for the Swirly
  19.     // brush:
  20.     int MX,MY;
  21.     double T=0;
  22.     // Here is something for the KeyTyped routine if you're entering text
  23.     // onto the canvas:
  24.     int A,Z,TX,TY;
  25.     // Now, just in case you want to type something on the package, there'll have
  26.     // to be a String type thingymebob in the program somewhere, hence we need
  27.     // to declare that right about now:
  28.     String S$="";
  29.     // Right, now the above will set a condition to draw different shapes,
  30.     // which will either be filled or not. The following two are used to set
  31.     // the main parameters for the shape size:
  32.     int XAxis,YAxis;
  33.     // and now we have two sets of RGB values, the first set is for the background
  34.     // colour and the second is for the foreground colour, ie, what you pain with:
  35.     int R,G,B,R1,G1,B1;
  36.     // Specifically, when there's been a change to the background value,
  37.     // we need to tell it later to stop it over-writing what's been drawn
  38.     // already, so let's set an integer for a condition later on:
  39.     int BackChange;
  40.     // These two integers will pass the set width and height through them:
  41.     int width,height;
  42.     // This is to set what part of the screen you may draw from, because of the
  43.     // buttons at the top, we have 86 scan-lines used:
  44.     int MinX,MinY;
  45.     // We need a quick help file too, so we'll set up an integer to test for that
  46.     // condition:
  47.     int Help;
  48.     // Okay, let's add some kick-ass buttons:
  49.     Button Fill1=new Button("Fill on/off");
  50.     Button Rect1=new Button("Rectangle");
  51.     Button Oval1=new Button("Oval");
  52.     Button RoundRect1=new Button("Rounded rect");
  53.     Button Swirl1=new Button("Swirl");
  54.     Button Str1=new Button("Text");
  55.     Button Help1=new Button("Help");
  56.     // Mint, and now we need to have some input boxes, and we also need to
  57.     // label them up, don't we...??? or something :-P
  58.     TextField RedFore=new TextField("255",3);
  59.     Label label_RedFore=new Label("Red Foreground:");
  60.     TextField GreenFore=new TextField("255",3);
  61.     Label label_GreenFore=new Label("Green Foreground:");
  62.     TextField BlueFore=new TextField("255",3);
  63.     Label label_BlueFore=new Label("Blue Foreground:");
  64.     TextField RedBack=new TextField("000",3);
  65.     Label label_RedBack=new Label("Red Background:");
  66.     TextField GreenBack=new TextField("000",3);
  67.     Label label_GreenBack=new Label("Green Background:");
  68.     TextField BlueBack=new TextField("000",3);
  69.     Label label_BlueBack=new Label("Blue Background:");
  70.     TextField BW=new TextField("30",4);
  71.     Label label_BW=new Label("Brush Width:");
  72.     TextField BH=new TextField("30",4);
  73.     Label label_BH=new Label("Brush Height:");
  74.     // Now here is where we declare our back buffer and main canvas:
  75.     Image backbuffer;
  76.     Graphics backg;
  77.     // Okay, we need to initialize the above variables and set things in action:
  78.     public void init()
  79.     {
  80.         // As you can see, we're using the variables above, one is on and
  81.         // zero is off, like in a boolean that I couldn't get to work!
  82.         Fill=1;Oval=0;Rect=0;RoundRect=0;Swirl=0;Str=1;
  83.         // Right, now to set the default RGB values:
  84.         R=0;G=0;B=0;R1=255;G1=255;B1=255;
  85.         // Okay, so we have to set the defaule value for the
  86.         // condition to say that the background has been changed:
  87.         BackChange=0;
  88.         // Now let's set the minimum parameters that can be drawn to:
  89.         MinX=0;MinY=86;
  90.         // Okays, so now we needs to the the default size of the brush painty
  91.         // bit that will be 'drawn' on the canvas:
  92.         XAxis=30;YAxis=30;
  93.         // Here is where we get the width and height of the canvas:
  94.         width=getSize().width;height=getSize().height;
  95.         // Now, as we have buttons at the top, we need to add MinY to the
  96.         // canvas height:
  97.         height=height+MinY;
  98.         // Right, so those Swirly variables above need to do something now:
  99.         MX=width/2;
  100.         MY=height/2;
  101.         // Let's set the default help value:
  102.         Help=0;
  103.         // So we need to create a back buffer at the same width and height:
  104.         backbuffer=createImage(width,height);
  105.         // And of course we call the image *from* the back buffer!!!111ONE
  106.         backg=backbuffer.getGraphics();
  107.         // First, we need to add white to the background of the buttons and
  108.         // stuff:
  109.         backg.setColor(new Color(255,255,255));
  110.         backg.fillRect(MinX,0,width,MinY);
  111.         // So, we tell the program to set the background colour, sending it
  112.         // to the above sub-routine, drawing a rectangle of the same size
  113.         // and using the default background RGB colour:
  114.         backg.setColor(new Color(R,G,B));
  115.         backg.fillRect(MinX,MinY,width,height);
  116.         // Now I see where this is going, we need to set the foreground colour
  117.         // here:
  118.         backg.setColor(new Color(R1,G1,B1));
  119.         // Right, now let's have a look at them buttons!
  120.         Fill1.addActionListener(this);
  121.         add(Fill1);
  122.         Rect1.addActionListener(this);
  123.         add(Rect1);
  124.         Oval1.addActionListener(this);
  125.         add(Oval1);
  126.         RoundRect1.addActionListener(this);
  127.         add(RoundRect1);
  128.         Swirl1.addActionListener(this);
  129.         add(Swirl1);
  130.         // Okay, this button (Str1) not only has a mouse action, but also
  131.         // needs the KeyListener to be added because you type afterwards.
  132.         // If you don't add the KeyListener to this button, then you can
  133.         // click on it but not type afterwards :-| Took me ages to work out
  134.         // and then I thought "What if I..." and blimey! It worked :D
  135.         Str1.addActionListener(this);
  136.         Str1.addKeyListener(this);
  137.         add(Str1);
  138.         // And before the text input boxes, we need the help button:
  139.         Help1.addActionListener(this);
  140.         add(Help1);
  141.         // Right, now let's add the text fields:
  142.         // And let's not forget to tell Java that they are both 'Actionable'
  143.         // and 'Typeable' (hoping that this works:
  144.         add(label_RedFore);RedFore.addActionListener(this);RedFore.addKeyListener(this);add(RedFore);
  145.         add(label_GreenFore);GreenFore.addActionListener(this);GreenFore.addKeyListener(this);add(GreenFore);
  146.         add(label_BlueFore);BlueFore.addActionListener(this);BlueFore.addKeyListener(this);add(BlueFore);
  147.         add(label_RedBack);RedBack.addActionListener(this);RedBack.addKeyListener(this);add(RedBack);
  148.         add(label_GreenBack);GreenBack.addActionListener(this);GreenBack.addActionListener(this);add(GreenBack);
  149.         add(label_BlueBack);BlueBack.addActionListener(this);BlueBack.addActionListener(this);add(BlueBack);
  150.         add(label_BW);BW.addActionListener(this);BW.addActionListener(this);add(BW);
  151.         add(label_BH);BH.addActionListener(this);BH.addActionListener(this);add(BH);
  152.         // As this is an 'object' we need to add the mouse listeners to 'this'
  153.         addMouseListener(this);
  154.         addMouseMotionListener(this);
  155.         // Okay, so here's a bit of an anomoly in Java - because you've got a
  156.         // MouseListener and MouseMotionListener active, an Applet can't focus
  157.         // on the two things at once - because it sux - so we need to remind
  158.         // it to set its' focus to different things, like the keyboard. You do
  159.         // this with the following before adding the KeyListener:
  160.         setFocusable(true);
  161.         addKeyListener(this);
  162.     }
  163.     public void mouseMoved (MouseEvent e)
  164.     {
  165.         // Okays, so let's show the status of X and Y axis, innit
  166.         int x=e.getX();
  167.         int y=e.getY();
  168.         showStatus("Donkeysoft Sketchpad V2.0, mouse at: "+x+" "+y);
  169.         e.consume();
  170.     }
  171.     public void mouseClicked (MouseEvent e)
  172.     {
  173.         int x=e.getX();
  174.         int y=e.getY();
  175.         if (Str==1 && y>MinY)
  176.         {
  177.             TX=x;
  178.             TY=y;
  179.             S$="";
  180.             repaint();
  181.             e.consume();
  182.             return;
  183.         }
  184.         // As above, but this is a mouse click-and-drag rather than a single
  185.         // click :-)
  186.         if (y<MinY)
  187.         {
  188.             return;
  189.         }
  190.         backg.setColor(new Color(R1,G1,B1));
  191.         // And now we need to decide what's going to be drawn, so if the
  192.         // read integer is 1 then that means do it, like drawing rectangles
  193.         // and if Fill is 1 then it does a fill, otherwise you get an outline:
  194.         if (RoundRect==1 && Fill==1)
  195.         {
  196.             backg.fillRoundRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis,XAxis/2,YAxis/2);
  197.         }
  198.         if (RoundRect==1 && Fill==0)
  199.         {
  200.             backg.drawRoundRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis,XAxis/2,YAxis/2);
  201.         }
  202.         if (Rect==1 && Fill==1)
  203.         {
  204.             backg.fillRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  205.         }
  206.         if (Rect==1 && Fill==0)
  207.         {
  208.             backg.drawRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  209.         }
  210.         if (Oval==1 && Fill==1)
  211.         {
  212.             backg.fillOval(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  213.         }
  214.         if (Oval==1 && Fill==0)
  215.         {
  216.             backg.drawOval(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  217.         }
  218.         // This bit writes something to the status bar:
  219.         showStatus("Donkeysoft Sketchpad V2.0, mouse at: "+x+" "+y);
  220.         // Now let's clear the area behind the buttons, just in case:
  221.         backg.setColor(new Color(255,255,255));
  222.         backg.fillRect(MinX,0,width,MinY);
  223.         // Now we call a repaint and consume this mouse action or it'll repeat.
  224.         repaint();
  225.         e.consume();
  226.     }
  227.     public void mouseDragged (MouseEvent e)
  228.     {
  229.         // As above, but this is a mouse click-and-drag rather than a single
  230.         // click :-)
  231.         int x=e.getX();
  232.         int y=e.getY();
  233.         if (y<MinY)
  234.         {
  235.             return;
  236.         }
  237.         backg.setColor(new Color(R1,G1,B1));
  238.         if (RoundRect==1 && Fill==1)
  239.         {
  240.             backg.fillRoundRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis,XAxis/2,YAxis/2);
  241.         }
  242.         if (RoundRect==1 && Fill==0)
  243.         {
  244.             backg.drawRoundRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis,XAxis/2,YAxis/2);
  245.         }
  246.         if (Rect==1 && Fill==1)
  247.         {
  248.             backg.fillRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  249.         }
  250.         if (Rect==1 && Fill==0)
  251.         {
  252.             backg.drawRect(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  253.         }
  254.         if (Oval==1 && Fill==1)
  255.         {
  256.             backg.fillOval(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  257.         }
  258.         if (Oval==1 && Fill==0)
  259.         {
  260.             backg.drawOval(x-(XAxis/2),y-(YAxis/2),XAxis,YAxis);
  261.         }
  262.         // Okay, now let's try to add the Swirly brush code:
  263.         if (Swirl==1)
  264.         {
  265.             backg.setColor(new Color(R1,G1,B1));
  266.             int DX=x-MX;
  267.             int DY=y-MY;
  268.             T+=Math.sqrt(DX*DX+DY*DY)/20;
  269.             if(T>2*Math.PI)
  270.             {
  271.                 T-=2*Math.PI;
  272.             }
  273.             backg.drawLine(x,y,x+(int)(15*Math.cos(T)),y+(int)(15*Math.sin(T)));
  274.             MX=x;
  275.             MY=y;
  276.         }
  277.         showStatus("Donkeysoft Sketchpad V2.0, mouse at: "+x+" "+y);
  278.         // Now let's clear the area behind the buttons, just in case:
  279.         backg.setColor(new Color(255,255,255));
  280.         backg.fillRect(MinX,0,width,MinY);
  281.         repaint();
  282.         e.consume();
  283.     }
  284.     public void keyTyped (KeyEvent e)
  285.     {
  286.         if (Str!=1)
  287.         {
  288.             return;
  289.         }
  290.         // Okay, let's get the keyboard input :-)
  291.         char C$=e.getKeyChar();
  292.         Z=C$;
  293.         A=S$.length();
  294.         // We need to check two conditions, one is whether or not there has
  295.         // been a keypress, and the other is to check the integer value of
  296.         // that keypress to make sure that it's not equal to 8, which is
  297.         // the delete key!
  298.         if(C$!=KeyEvent.CHAR_UNDEFINED && Z!=8 && Z!=32 && Z!=10)
  299.         {
  300.             S$=S$+C$;
  301.             Z=C$;
  302.             backg.setColor(new Color(R1,G1,B1));
  303.             backg.drawString(S$,TX,TY);
  304.             showStatus("Donkeysoft Sketchpad V2.0, Key value is ("+Z+")");
  305.             repaint();
  306.             e.consume();
  307.         }
  308.         // Right, so what do we do if the delete key is pressed?
  309.         // Well, here's a good one, let's take the value of the background
  310.         // colour and redraw the string first, this makes it invisible,
  311.         // and then let's make the string one character less before redrawing
  312.         // it onto the screen, thus elimenating the last char, ie, the one
  313.         // that has been deleted. Magic!
  314.         else
  315.             if(Z==8 && A>0)
  316.             {
  317.                 backg.setColor (new Color(R,G,B));
  318.                 backg.drawString(S$,TX,TY);
  319.                 S$=S$.substring(0,A-1);
  320.                 backg.setColor (new Color(R1,G1,B1));
  321.                 backg.drawString(S$,TX,TY);
  322.                 showStatus("Donkeysoft Sketchpad V2.0, Key value is ("+Z+")");
  323.                 repaint();
  324.                 e.consume();
  325.             }
  326.             else
  327.                 // For some reason, I had an anomoly with the space, because
  328.                 // if you press space after clicking on the text button,
  329.                 // what happens is that you've pressed the button again and
  330.                 // it seems to reset the parameters, so we need a work-around
  331.                 // which physically adds a space to the string S$:
  332.                 if(Z==32)
  333.                 {
  334.                     S$=S$+" ";
  335.                     Z=C$;
  336.                     backg.setColor(new Color(R1,G1,B1));
  337.                     backg.drawString(S$,TX,TY);
  338.                     showStatus("Donkeysoft Sketchpad V2.0, Key value is ("+Z+")");
  339.                     repaint();
  340.                     e.consume();
  341.                 }
  342.                 else
  343.                     // And this is if you hit return, but there is one condition
  344.                     // which will stop you going off the canvas, list this:
  345.                     if(Z==10 && (TY-28<=height-MinY))
  346.                         // Of course, there's an ofset of 28 because we add
  347.                         // 14 to the Y axis for each carriage return, so in
  348.                         // other words, 14 is added to TY if it's smaller than
  349.                         // the bottom of the canvas - do the maths! Okay, it
  350.                         // doesn't seem to work, but in theory it should.
  351.                     {
  352.                         TY=TY+14;
  353.                         Z=C$;
  354.                         // Okay, so let's clear S$ or that will be drawn to
  355.                         // the next line
  356.                         S$="";
  357.                         backg.setColor(new Color(R1,G1,B1));
  358.                         showStatus("Donkeysoft Sketchpad V2.0, Key value is ("+Z+")");
  359.                         repaint();
  360.                         e.consume();
  361.                     }
  362.     }
  363.     public void keyPressed(java.awt.event.KeyEvent keyEvent)
  364.     {
  365.     }
  366.     public void keyReleased(java.awt.event.KeyEvent keyEvent)
  367.     {
  368.     }
  369.     // Yo! This is where the buttons *should* work, one hopes.
  370.     public void actionPerformed(ActionEvent e)
  371.     {
  372.         // Integers to change here are as follows:
  373.         // Fill (for whether it's draw or fill), Oval for a rounded
  374.         // brush, Rect for a square brush, RoundRect for square with rounded
  375.         // sides, swirl for the swirly brish (to be added) and finally
  376.         // Str for text input to canvas
  377.         // First, we'll check for fill on or not:
  378.         if (e.getSource()==Fill1 && Fill==1)
  379.         {
  380.             Fill=0;
  381.             showStatus("Donkeysoft Sketchpad V2.0, Fill is now OFF");
  382.             repaint();
  383.             return;
  384.         }
  385.         if (e.getSource()==Fill1 && Fill==0)
  386.         {
  387.             Fill=1;
  388.             showStatus("Donkeysoft Sketchpad V2.0, Fill is now ON");
  389.             repaint();
  390.             return;
  391.         }
  392.         // Now, we'll have a look if the square brush has been selected:
  393.         //Rect1, Oval1, RoundRect1, Swirl1, String1
  394.         if (e.getSource()==Rect1)
  395.         {
  396.             Rect=1;Oval=0;RoundRect=0;Swirl=0;Str=0;
  397.             showStatus("Donkeysoft Sketchpad V2.0, Rectangle brush selected");
  398.             repaint();
  399.             return;
  400.         }
  401.         if (e.getSource()==Oval1)
  402.         {
  403.             Rect=0;Oval=1;RoundRect=0;Swirl=0;Str=0;
  404.             showStatus("Donkeysoft Sketchpad V2.0, Rectangle brush selected");
  405.             return;
  406.         }
  407.         if (e.getSource()==RoundRect1)
  408.         {
  409.             Rect=0;Oval=0;RoundRect=1;Swirl=0;Str=0;
  410.             showStatus("Donkeysoft Sketchpad V2.0, Rounded-edged rectangle brush selected");
  411.             return;
  412.         }
  413.         if (e.getSource()==Swirl1)
  414.         {
  415.             Rect=0;Oval=0;RoundRect=0;Swirl=1;Str=0;
  416.             showStatus("Donkeysoft Sketchpad V2.0, Swirl brush selected");
  417.             return;
  418.         }
  419.         if (e.getSource()==Str1)
  420.         {
  421.             Rect=0;Oval=0;RoundRect=0;Swirl=0;Str=1;
  422.             showStatus("Donkeysoft Sketchpad V2.0, text brush selected");
  423.             return;
  424.         }
  425.         // Let's see if the help button has been pressed:
  426.         if (e.getSource()==Help1)
  427.         {
  428.             Help=1;
  429.             return;
  430.         }
  431.         // Okay, so here we need to check if the RGB value entered is valid (ie, between 0 and 255)
  432.         // convert it into an Integer and store it in the relevane variable.
  433.         // There is also a condition to check whether or not the text brush is selected because you can't
  434.         // enter a value into the text field whilst that is switched on or you'll be entering the number
  435.         // onto the canvas, which is what we don't want.
  436.         if (e.getSource()==RedFore && Integer.parseInt(RedFore.getText())>-1 && Integer.parseInt(RedFore.getText())<256 && Str!=1)
  437.         {
  438.             R1=Integer.parseInt(RedFore.getText());
  439.             showStatus("Donkeysoft Sketchpad V2.0, red foreground colour value changed");
  440.             return;
  441.         }
  442.         if (e.getSource()==GreenFore && Integer.parseInt(GreenFore.getText())>-1 && Integer.parseInt(GreenFore.getText())<256 && Str!=1)
  443.         {
  444.             G1=Integer.parseInt(GreenFore.getText());
  445.             showStatus("Donkeysoft Sketchpad V2.0, green foreground colour value changed");
  446.             return;
  447.         }
  448.         if (e.getSource()==BlueFore && Integer.parseInt(BlueFore.getText())>-1 && Integer.parseInt(BlueFore.getText())<256 && Str!=1)
  449.         {
  450.             B1=Integer.parseInt(BlueFore.getText());
  451.             showStatus("Donkeysoft Sketchpad V2.0, blue foreground colour value changed");
  452.             return;
  453.         }
  454.         if (e.getSource()==RedBack && Integer.parseInt(RedBack.getText())>-1 && Integer.parseInt(RedBack.getText())<256 && Str!=1)
  455.         {
  456.             R=Integer.parseInt(RedBack.getText());
  457.             showStatus("Donkeysoft Sketchpad V2.0, red background colour value changed");
  458.             BackChange=1;
  459.         }
  460.         if (e.getSource()==GreenBack && Integer.parseInt(GreenBack.getText())>-1 && Integer.parseInt(GreenBack.getText())<256 && Str!=1)
  461.         {
  462.             G=Integer.parseInt(GreenBack.getText());
  463.             showStatus("Donkeysoft Sketchpad V2.0, green background colour value changed");
  464.             BackChange=1;
  465.         }
  466.         if (e.getSource()==BlueBack && Integer.parseInt(BlueBack.getText())>-1 && Integer.parseInt(BlueBack.getText())<256 && Str!=1)
  467.         {
  468.             B=Integer.parseInt(BlueBack.getText());
  469.             showStatus("Donkeysoft Sketchpad V2.0, blue background colour value changed");
  470.             BackChange=1;
  471.         }
  472.         // Okay, now let's deal with the brush width and height:
  473.         if (e.getSource()==BW && Integer.parseInt(BW.getText())>-1 && Integer.parseInt(BW.getText())<256)
  474.         {
  475.             XAxis=Integer.parseInt(BW.getText());
  476.             showStatus("Donkeysoft Sketchpad V2.0, brush width value changed");
  477.             return;
  478.         }
  479.         if (e.getSource()==BH && Integer.parseInt(BH.getText())>-1 && Integer.parseInt(BH.getText())<256)
  480.         {
  481.             YAxis=Integer.parseInt(BH.getText());
  482.             showStatus("Donkeysoft Sketchpad V2.0, brush height value changed");
  483.             return;
  484.         }
  485.         if (BackChange==1)
  486.         {
  487.             backg.setColor(new Color(R,G,B));
  488.             backg.fillRect(MinX,MinY,width,height);
  489.             BackChange=0;
  490.         }
  491.         repaint();
  492.     }
  493.     // Okay, so this is there the back buffer is drawn to and syncronised
  494.     public void update (Graphics g)
  495.     {
  496.         g.drawImage(backbuffer,0,0,this);
  497.         if (Help==1)
  498.         {
  499.             int TempX=2, TempY=100, NewLine=14;
  500.             g.setColor(new Color(0,0,0));
  501.             g.fillRect(MinX,MinY,width,height);
  502.             g.setColor (new Color(255,255,255));
  503.             g.drawString ("Welcome to Donkeysoft's Sketchpad Applet, by Shaun Bebbington (C) MMX",TempX,TempY);
  504.             TempY=TempY+NewLine;
  505.             g.drawString ("------------------------------------------------------------------------------------------------------",TempX,TempY);
  506.             TempY=TempY+NewLine;
  507.             g.drawString ("This program is freeware, and the source code is available online",TempX,TempY);
  508.             TempY=TempY+NewLine;
  509.             g.drawString ("somewhere, so please feel free to have a play with it and make it do",TempX,TempY);
  510.             TempY=TempY+NewLine;
  511.             g.drawString ("more stuff. Okay, so here's a quick guide:",TempX,TempY);
  512.             TempY=TempY+NewLine;
  513.             g.drawString ("Starting from top-left, the Fill on/off button will allow you to draw",TempX,TempY);
  514.             TempY=TempY+NewLine;
  515.             g.drawString ("solid or outlined shapes that follow, which are rectangles, ovals,",TempX,TempY);
  516.             TempY=TempY+NewLine;
  517.             g.drawString ("or rectangles with rounded edges. The Swirl brush is some polite",TempX,TempY);
  518.             TempY=TempY+NewLine;
  519.             g.drawString ("mathematics, I've added it because I thought it looked good! By",TempX,TempY);
  520.             TempY=TempY+NewLine;
  521.             g.drawString ("clicking Text you will be able to enter text onto the canvas - just",TempX,TempY);
  522.             TempY=TempY+NewLine;
  523.             g.drawString ("click anywhere on the canvas and start typing. Obviously, you know",TempX,TempY);
  524.             TempY=TempY+NewLine;
  525.             g.drawString ("what help does. You are able to change the RGB values of the",TempX,TempY);
  526.             TempY=TempY+NewLine;
  527.             g.drawString ("foreground and background colours by entering a value in each between",TempX,TempY);
  528.             TempY=TempY+NewLine;
  529.             g.drawString ("zero and 255, giving 24-bit colour, have a play - it is fun! But",TempX,TempY);
  530.             TempY=TempY+NewLine;
  531.             g.drawString ("note that whenever you change the background colour, the whole canvas",TempX,TempY);
  532.             TempY=TempY+NewLine;
  533.             g.drawString ("is repainted to that colour and anything you've drawn is lost.",TempX,TempY);
  534.             TempY=TempY+NewLine;
  535.             g.drawString ("Entering a new brush width or height will change the relevant size",TempX,TempY);
  536.             TempY=TempY+NewLine;
  537.             g.drawString ("of the brush with exception to the text and swirl, again the minimum",TempX,TempY);
  538.             TempY=TempY+NewLine;
  539.             g.drawString ("value is zero and maximum is 255. You can not enter a new value to",TempX,TempY);
  540.             TempY=TempY+NewLine;
  541.             g.drawString ("any of the input boxes whilst you have the text brush selected",TempX,TempY);
  542.             TempY=TempY+NewLine;
  543.             g.drawString ("becuase you can't type on the canvas and in the text box at the same",TempX,TempY);
  544.             TempY=TempY+NewLine;
  545.             g.drawString ("Time. Also, *don't forget* to press enter after entering a new value or it",TempX,TempY);
  546.             TempY=TempY+NewLine;
  547.             g.drawString ("won't change.",TempX,TempY);
  548.             TempY=TempY+NewLine;
  549.             g.drawString ("Finally, and most importantly, have a look and the code and have fun! SB :-)",TempX,TempY);
  550.             Help=0;
  551.         }
  552.         if (Str==1 && R1/2>0 && G1/2>0 && B1/2>0)
  553.         {
  554.             // Right, let's have a different colour for the text marker
  555.             // than the text to make it a bit clearer:
  556.             g.setColor(new Color (R1/2,G1/2,B1/2));
  557.             g.drawLine(TX,TY,TX,TY-10);
  558.             g.drawLine(TX,TY,TX+10,TY);
  559.         }
  560.         else
  561.             if (Str==1 && (R1/2<=0 || G1/2<=0 || B1<=0))
  562.             {
  563.                 // Right, well we can't do an RGB colour smaller than zero
  564.                 // so let's set the new colour to zero for each RGB value:
  565.                 g.setColor(new Color (0,0,0));
  566.                 g.drawLine(TX,TY,TX,TY-10);
  567.                 g.drawLine(TX,TY,TX+10,TY);
  568.             }
  569.         getToolkit().sync();
  570.     }
  571.     // This then updates (or flips) the back buffer so we can see the last
  572.     // action added to the canvas, good, innit?
  573.     public void paint (Graphics g)
  574.     {
  575.         update(g);
  576.     }
  577.     // All this crap here needed to be added to this program or Java doesn't
  578.     // like it and it takes *hours* to work this out, even though it's not
  579.     // actually doing anything whatsoever. I'd like to meet the sadistic
  580.     // idiots who created all of these useless bits in Java, I'm sure it's
  581.     // been created just to annoy people rather than being in any way
  582.     // whatsoever helpful.
  583.     public void mouseEntered(java.awt.event.MouseEvent mouseEvent)
  584.     {
  585.     }
  586.     public void mouseExited(java.awt.event.MouseEvent mouseEvent)
  587.     {
  588.     }
  589.     public void mousePressed(java.awt.event.MouseEvent mouseEvent)
  590.     {
  591.     }
  592.     public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
  593.     {
  594.     }
  595. }
  596. // This assignment was created by Shaun Bebbington to learn about them
  597. // Applets (c) 2010 Donkey Soft, version 2.0
  598.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement