Drawing character inside rectangle

Hi!
I have the following problem. I have a string and my task is to be able to draw every character of the string in every rectangle. For example I have a string:
String = ("GCATCGCAGAGAGT");
So now I will have 14 characters inside 14 rectangles. My question is how to do that? Please help me to solve it.

This is my code. There's still error in it. It can not show the rectangle and also the characters. Could you fix my code? I am still a beginner in this field
I am sorry if my code is not formatted as well, because I am a new comer in this forum. So please help me to solve my problem, I expecting a lot from you.
/** Here is my code **/
package brute_force;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
* BorderLayoutDemo.java
public class BruteForceAnimation4 extends JPanel{
          /** Variable for drawing character inside rectangle **/
          private String[] mSourceString = {"G","C","A","T","C","G","C","A","G","A","G","A","G","T"};
          private String[] mPatternString = {"G","C","A","G","A","G","A","G"};
          /** This is variables to draw the rectangle **/
          private int xPosSource = 40;
          private int yPosSource = 100;
          private int xPosPattern = 80;
          private int yPosPattern = 80;
     /** constants for predefined colors */
     private static final Color lightBlue = new Color(153, 204, 255);
     public BruteForceAnimation4()
     super();
     public static void addComponentsToPane(Container pane) {
     JLabel lblTitle = new JLabel("Brute Force String Searching
Algorithm", SwingConstants.CENTER);
     String bruteForceCode[] = {
     "int count = 0", //0
     "int m = mPattern.length();", //1
     "int n = mSource .length();", //2
     "outer:", //3
     " for (int i = 0; i <= n - m; ++i) {", //4
     " for (int k = 0; k < m; ++k) {", //5
     " if (mPattern.charAt(k) != mSource.charAt(i + k)) {", //6
     " continue outer;", //7
     " }", //8
     " }", //9
     " ++count;", //10
     " }", //11
     " return count;", //12
     "}" //13
     JList list = new JList(bruteForceCode); // a container for pseud code
     JButton cmdRun = new JButton("Run");
     JButton cmdStep = new JButton("Step");
     //Set the title of the applet
     lblTitle.setFont(new Font("Serif", Font.BOLD, 18));
     JPanel buttons = new JPanel();
     buttons.add(cmdRun);
     buttons.add(cmdStep);
     buttons.setBackground(lightBlue);
     //Set the size and border of list (JList component)
     Border etch = BorderFactory.createEtchedBorder();
     list.setBorder(BorderFactory.createTitledBorder(etch, "Brute Force
Code"));
     JPanel listPanel = new JPanel();
     listPanel.add(list);
     listPanel.setBackground(lightBlue);
     list.setBackground(lightBlue);
     BruteForceAnimation4 border = new BruteForceAnimation4();
          pane.add(lblTitle, BorderLayout.NORTH);
     pane.add(border, BorderLayout.CENTER);
     pane.add(listPanel, BorderLayout.EAST);
     pane.add(buttons, BorderLayout.SOUTH);
     pane.setBackground(lightBlue);
     public void paintComponent(Graphics g)
     super.paintComponent(g);
     Graphics2D g2 = (Graphics2D) g;
     setBackground(lightBlue);
     drawSourceString(g2, mSourceString);          
/** this is the method to draw character inside rectangles **/
/** but it still wrong **/
     public void drawSourceString(Graphics2D g2,String[] mSource)
          if (mSource == null)
               return;
          for (int i=0; i < mSource.length; i++)
               g2.drawRect(xPosSource, yPosSource, 60, 40);
               g2.drawString(mSource,40,40);                              
               xPosSource += 30;
//This is to count the length of the the Source
               System.out.println("Your length" +mSource.length);
     public static void main(String[] args) {
     //Create and set up the window.
     JFrame frame = new JFrame("Brute Force Algorithm");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //Set up the content pane.
     addComponentsToPane(frame.getContentPane());
     //Use the content pane's default BorderLayout. No need for
     //setLayout(new BorderLayout());
     //Display the window.
     frame.pack();
          frame.setSize(800, 600);
     frame.setVisible(true);

Similar Messages

  • Speed issue when drawing field of Rectangles

    I'm working on a fullscreen java app that consists of a 320x320 field of randomly-colored dots, a variable percentage of which should eventually move in concert at up to 100 fps. Right now I'm simply working on drawing a varying field of dots on the screen at that speed. I'm using multiple buffers with the help of the MultiBufferTest example from Sun's Full Screen Exclusive Mode API tutorial. The demo runs great, pages flipping at what appears to be the speed at which I need my graphics to appear on the screen, but the demo draws only one Rectangle.
    The problem I'm having seems to be the speed at which my 102400 Rectangles are being drawn on one of the back buffers before being flipped onto the screen. Right now I'm working with 3 buffers, but it doesn't seem to matter how many I use; the speed at which the field appears to plateau at around 1 fps. Some thoughts:
    * My random color generation code is outside of the rendering loop.
    * I've casted the Graphics object into a Graphics2D object g2, but that hasn't helped.
    * The Rectangles are drawn inside nested for loops by row (r) and column (c) using g2.fillRect(c * mSide, r * mSide, mSide, mSide); where mSide is the side length of each Rectangle.
    * Is it possible to draw all the frames into a Vector of buffers before the 'animation' begins? Presumably it would still take around 1 second to generate each frame that will appear, so that probably wouldn't work too well.
    * I have the O'Reilly book Java 2D Graphics, but it doesn't help much in this situation.
    I'm a novice at Java and a novice at graphics programming to boot, so is there anyone out there that can give me some advice on how to speed up the graphics generation?

    I'm working on a fullscreen java app that consists of a 320x320 field of randomly-colored dots, a variable percentage of which should eventually move in concert at up to 100 fps. Right now I'm simply working on drawing a varying field of dots on the screen at that speed. I'm using multiple buffers with the help of the MultiBufferTest example from Sun's Full Screen Exclusive Mode API tutorial. The demo runs great, pages flipping at what appears to be the speed at which I need my graphics to appear on the screen, but the demo draws only one Rectangle.
    The problem I'm having seems to be the speed at which my 102400 Rectangles are being drawn on one of the back buffers before being flipped onto the screen. Right now I'm working with 3 buffers, but it doesn't seem to matter how many I use; the speed at which the field appears to plateau at around 1 fps. Some thoughts:
    * My random color generation code is outside of the rendering loop.
    * I've casted the Graphics object into a Graphics2D object g2, but that hasn't helped.
    * The Rectangles are drawn inside nested for loops by row (r) and column (c) using g2.fillRect(c * mSide, r * mSide, mSide, mSide); where mSide is the side length of each Rectangle.
    * Is it possible to draw all the frames into a Vector of buffers before the 'animation' begins? Presumably it would still take around 1 second to generate each frame that will appear, so that probably wouldn't work too well.
    * I have the O'Reilly book Java 2D Graphics, but it doesn't help much in this situation.
    I'm a novice at Java and a novice at graphics programming to boot, so is there anyone out there that can give me some advice on how to speed up the graphics generation?

  • Cannot draw a transparent rectangle in Flash CS4

    Hi,
    In Flash CS4, when I draw a rectangle (or circle, or anything) with a color that has 0 alpha, nothing is drawn. Also, if I select a piece of drawing and change the color to 0 alpha, the drawing (e.g. rectangle) disappears!!
    Is there any way to disable this astonishingly stupid behaviour?
    I know I can draw a non-transparent rectangle, convert it to movie clip and set the movie clip's alpha to 0, but I'd like to avoid this.

    No it isn't a feature. It is definitely a bug. I experienced this once before. I had the part where if I selected something that already existed and changed its fill to alpha 0 then it just disappeared. And I too thought it was somebody had made a really bad programming choice when writing CS4.
    But then it went away. I've never figured out what caused it or why. I think at the time my response was just to set the alpha low (1%) with a thought like, "Well, that is hella annoying, I don't have time to deal with it now I'll come back and figure it out later." And then it just got better on its own.
    Sorry I don't have anything specific other than to tell you that you aren't alone and you aren't imagining it!
    You have updated to 10.0.2? I can't remember if it happened to me before the update or not. Are you on a Mac or PC? I also can't remember if this happened to me at work or home, so I don't know which one I saw it on. BTW I just tried it on my Mac and I can draw and/or change a shape to fill alpha zero.

  • Paint inside rectangle shape

    I am confused about following.  How to paint inside rectangle with paint brush without going outside my edges. 
    I create rectangle with rectangle tool and now i would like to use brush inside it but it keeps going outside.  How do i prevent that?
    is the only way to do that to use marquette tool? i tried that but cant seem to be able to select all of my shape. 
    Can someone give me some suggestions please

  • OCR labview code-character bounding rectangle

    NI didn't leak the codes and examples fully for Vision Assistant so I have to use the assistant whenever I train some characters.
    I want to add the simple training routine to my main program.
    As a start point, I would like to detect the character bounding rectangle of OCR object (like a red box of attachment) before reading a character set.
    Is there any related vi for this work?
    labmaster.
    *)NI Read LCD/LED.vi didn't operate for my purpose. gave up after investing time and various camera.
    Solved!
    Go to Solution.
    Attachments:
    yahoo.png ‏9 KB

    NI labview provided the code in OCR panel.

  • How to insert a new line character inside CDATA tag in the source xml data file?

    values for form fields in the xml data file is contained inside CDATA tags which is an Unparsed Format.
    Eg: [CDATA[IBM-01 ~ DSHFSJDSJ ~ FGFGFJ, ~ VA 665665]] delimited by "~" char
    Actual o/p:-
    IBM-01 ~ DSHFSJDSJ ~ FGFGFJ, ~ VA 665665
    Expected o/p is like :-
    IBM-01
    DSHFSJDSJ
    FGFGFJ,
    VA 665665
    live cycle product does not interpret ~ as a newline character. Please suggest which character should be used instead inside CDATA section or if there is any other way to fix this?

    I do not have any problem while using IE's XML parser
    for XML+XSLT merging.That is because IE's parser does not implement XML correctly.
    But when I use JAXP's Transformer object, it does not
    preserve the new lines inside attribute values and
    converts those into white spaces.That is exactly what the XML specifications say should happen.
    >
    ----If you have text that contains newlines, you
    should put it in an element, not in
    ----an attribute.
    That would be my last solution. But I'd really hate
    to change my logic just 'coz JAXP is not capable of
    handling new lines inside attribute values. I may be
    wrong... but If IE can keep those then there has to
    be a way to do the same from server side merging....Sure. Write your own parser with the same bug in it. But you don't have any right to demand that other people supply you with parsers that work incorrectly.

  • Using basicStroke to draw the INSIDE of a polygon

    hello
    i have a polygon that i want to trace the inside of... using:
    g2.setStroke( new BasicStroke( 20, //float width,
    BasicStroke.CAP_SQUARE, //int cap,
    BasicStroke.JOIN_MITER,
    1,
    new float[] { 12, 12 },
    1
    g2.draw( myRect );
    this code traces the shape "on the line", and since the stroke width is 20 pixels, it is painting both inside and outside of the shape itself.
    i would like to trace the inside of the shape. or for that matter, the outside of the shape...
    any ideas?
    thanks
    ERIK!

    First draw the shape using g.fill() and a
    non-transparent color. Then set an alpha composite
    with the rule SRC_IN, and redraw the shape using the
    desired stroke. Only the part of the stroke inside
    the filled area will be drawn. Use SRC_OUT to draw
    outside the shape. If you're drawing on top of
    existing graphics, you may have to use a BufferedImage
    as a temporary work area to composite the shape and
    then draw the image to your graphics context.thanks for the suggestion, although i believe that this will not render the outer edge of the stroke as intended...
    what i mean is, where you use the shape itself to mask the stroke, it will leave a not-as-pretty edge as you would get if from an un-masked basic stroke.
    thanks for the two suggestions though.

  • Drawing Tabs with Rectangle Primative Tool

    I changed the corner points in the Property Inspector to make
    the
    Rectangle Primative Tool create navigation tabs. The tabs
    were drawn in
    Object Mode.
    1. Why did it draw it in Object Mode by default?
    2. IS there a way to change this while drawing the shape, or
    is this
    just how this tool works?
    Thanks in advance.

    1) because it handy to keep you shapes contained as vector,
    until you want to break them apart, you can draw shapes on top of
    one another without them effecting the shape underneath, then when
    they are in position, if desired, you can break them apart and them
    union them into a single vector graphic.
    2) when you select the tool, click the Object Mode button at
    the bottom of the toolbar to toggle states.

  • Spark - Drawing a rounded rectangle with 3-sided border?

    I am upgrading to the Spark theme, and I am trying to draw a rectangle, with a corner radius of 20, with a border on only the top, right, and bottom sides.
    Basically, I want it to dock flush left in my application and extend out in a rounded rectangle.
    But I Cannot figure out how I would draw this in SVG? Anyone done this yet?

    Ned,
    Thank you for your response.  I apologize for the delay in my own response.
    I was seeing distortion in x direction as well.
    I was able to solve my problem using 9-slice scaling.  I used the scale9Grid property.

  • How to clip water surface easily? (Prevent drawing water inside boat)

    Hi,
    I have a water surface (blue j3d.utils.geometry.Box object) and a simple yacht model swimming in it. User can change camera position. The problem is that water is rendered inside the boat between sideboards (model is about 30% below water surface but bilge shouldn't be covered).
    How to prevent this? I know that OrderedGroup is not the answer from here: (http://forum.java.sun.com/thread.jspa?threadID=466312&messageID=2179052#2179052)
    I've searched web for help but with no results.
    Please help!
    S.T.

    I'm not entirely certain this will fix your problem, but try searching for DEPTH TEST FUNCTIONS or DEPTH BUFFERS. If you are using Java 3D instead of JOGL you will need to find out if there is a similar method to use. See if you can set the Java3D RenderingAttributes depth test function to ALWAYS for just that object. You will want to render your water first, then disable or change the mode of depth testing or clear the buffer and then render your boat.
    e.g.        gl.glDepthFunc(GL.GL_LEQUAL);
           or   gl.glDepthFunc(GL.GL_EQUAL);I don't remember which one you use, but it will draw on top of your water replacing any pixels on your screen taken up by the boat, essentially eliminating the rendered water inside the boat. Very similar method to what you would use to place an orthographically projected menu interface on top of a perspective background.
    Hope this helps steer you in the right direction.
    Message was edited by:
    CTTillman
    Message was edited by:
    CTTillman

  • Can't Draw a simple rectangle

    I figure there is something wrong with my installation of Edge Animate CC. When I try to draw any object on the stage nothing happens. The object just doesn't appear. When I close the project down and try to create a new project, the "New" option is greyed out in the file menu. When I try to save a project (even though there is nothing on the stage) I get an error.
    I tried uninstalling/installing 3 times and it still behaves the same way.
    Is there a way to make sure I get a clean installation of this product?

    Did you trying clearing the preference while un-installing and re-installing?
    You can as well trying clearing it manually and restart Animate and see if it resolves your problem.
    Guide to clearing preference
    http://helpx.adobe.com/edge-animate/kb/restore-preferences-edge-animate.html

  • Draw lines inside container

    Hi ,
    I have req like need to dispaly line end of application.To show the data on the UI.I have created a custom mxml component(Canvas).Inside this canvas i have created the controls inside VBox container.
    I need to display 5 line before end of the application.So if user scrolls the application at the end he can see 5 lines before it end.
    Please need sample code to show these line.Please help me.
    I tried with below code.But its not working.Please help me.
    <mx:VBox width="100%" verticalGap="5">
    -----------------Other Controls--   ---------------------
           <mx:HBox id="drawStLine2" width="100%" height="100%" initialize="drawLineInit()" />
    </mx:VBox>
    public function drawLineInit():void {
         var myShape:Shape = new Shape(); 
           myShape = new Shape() ;
           myShape.graphics.lineStyle(5, 0x990000, .75);  
           myShape.graphics.moveTo(100, 100);   
           myShape.graphics.lineTo(500, 500);
           drawStLine1.addChild(myShape);
    Thanks in advance

    I have to display like this(not dottted lines) .Its a thick line.
    Thanks,
    Saritha

  • Draw Rectangle to Canvas ?

    I am finding that working with drawing shape in Java is a bit hard to understand. I am hoping someone can help me out. I have wanting to draw a simple Rectangle to a Canvas. I am hoping that will give the user the look that a Rectangle has been drawn to the screen and not inside of a JFrame or anything like that.
    Here is my code that does not seam to work.
    Canvas can;
    Graphics g2;
    Rectangle r;
    public void drawShape()
           can = createCanvas();
           g2 = can.getGraphics();
           g2.drawRect(0, 0, 640, 480);
    //create canvas that I call from another class
    public Canvas createCanvas( )
              r.width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
              r.height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
              r.x = 0;
              r.y = 0;
              if(box == null)
                   box = new Canvas();
                   box.setBounds(r);
              return box;
         }

    simple demo, might start you off
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      public void buildGUI()
        JPanel p = new JPanel(){
          public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.drawString("alt-F4 to close",400,300);
            g.drawRect(300,200,300,200);
        p.setBackground(Color.WHITE);
        JFrame f = new JFrame();
        f.getContentPane().add(p);
        f.setUndecorated(true);
        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }more reading here
    [http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html]
    and this
    can.getGraphics();is generally a very bad way to do it

  • Drawing a rectangle

    I want to draw a rectangle - not a filled rectangle, I can do that but say a rectangle about 5 pixels wide that I can then drag to resize and use like a frame. The pre-defined shapes increase their line thickness as you make them bigger which is not what I want.
    I could of course draw an outer rectangle in colour and then a smaller white one inside to simulate the effect I want but I'm using transparency so I don't want a filled white area.
    Please tell me I've missed something simple!

    File>new> blank file
    Access rectangular marquee tool. In the tool's option bar, one can establish a fized size
    Edit>stroke. The width of the stroke can be configured in pixels.
    Any intervening color can be removed by selecting with magic wand tool

  • How do I get the rectangle tool to draw in the color I've selected?

    I'm quite new to indesign, so bear with me.
    I've selected a color with the eyedropper tool, and once I am about to draw using the rectangle tool, the color switches to grayscale. How do I change this?
    Thanks

    You've gotten the answer but may I suggest a couple of references?
    Sandee Cohen's Visual Quick Start Guide is the best $18 you'll ever spend: http://amzn.to/IfpRN3
    There are some excellent video courses on Lynda.com. This link will get you a one week free trial: http://bit.ly/fcGpiI
    Bob

Maybe you are looking for

  • Ipod mini opens auto run, not in itunes

    I have he problem that the ipod mini opens as a storage device G-drive, not in itunes, and the autoplay box opens up but does not allow you to choose itunes. To make it open in itunes I often have to restart my computer, open itunes then it opens. Th

  • Wireless printing with HP printer and Netgear Router

    I am a new MAC user, and I am trying to figure out how to set up my new MacBook wirelessly to my HP PSV 1600 printer. I have a Netgear router that is working great with my MacBook. I'm just unsure of how to connect my Macbook, Printer, and Router all

  • Advice on Creating Pedal Steel Guitar Instrument

    Hi, everyone. I am looking for some advice on creating an authentic Pedal Steel Guitar software instrument. I have all 4 Jam Packs, so would have access to any existing Guitar software instrument. I've played with the Jazz Chorus Electric, Twangy Ele

  • Acrobat 7 Professional Output Preview Preferences

    I think the new "Output Preview" tool in Acrobat 7 Professional is GREAT! Especially the ability to check "Total Ink Coverage". But, what I would like to see is the ability to set a preference for this tool. Seems it always defaults to 280. In our sh

  • HTTP Receiver

    Hello, I am trying to configure a IDOC -> XI -> HTTP scenario and i have hit a brick wall when coming to configure the HTTP receiver adapter. Is there anyone out there with some examples? Any help will be very much appreciated. Dimitris