Havin probs drawing a simple string

hi 2 all
i've got this simple applet,but it doesn't really what i want!i only see a gry rect!but he has to draw a string!
import java.applet.*;
import java.net.*;
import java.io.*;
import java.awt.*;
public class CCounter1 extends Applet {
Font anzeiger;
public void init() {
anzeiger=new Font("Arial",Font.BOLD,16);
public String readFile(String f) {
try {
String zahl1="";
String aLine = "";
URL source = new URL(getCodeBase(), f);
BufferedReader br =new BufferedReader(new InputStreamReader(source.openStream()));
while(null != (aLine = br.readLine()))
zahl1.concat(zahl1);
br.close();
return aLine;
catch(Exception e) {
e.printStackTrace();
return null;
public void paint(Graphics g){
setBackground(Color.gray);
g.setColor(Color.white);
setFont(anzeiger);
g.fillRect(100,100,100,100);
g.drawString(readFile("besucher.hansi"),10,20);
g.drawString("Hallo",200,200);

You set the color to white... fill the area and then paint a string (with the same white color)
first... set a color... fill it... then set another color... draw your string... done
Grtz David

Similar Messages

  • How to draw a simple pie chart?

    I want to draw a simple pie chart.
    I was wondering whether there already exists a method to allow me to do that in SDK 1.4.2. I saw on the net a method getPieChart( ).
    Do you know if its incorporated in SDK1.4.2 and how to draw the pie chart using this method. Can anybody guide me?
    Thanks.

    Have a look in your demos folder in your SDK, for example:
    C:\j2sdk1.4.2_04\demo\applets\GraphicsTest

  • Simple String Compression Functions

    Hi all !
    I need two simple String compression functions, like
    String compress(String what)
    and
    String decompress(String what)
    myString.equals(decompress(compress(myString)))
    should result in true.
    Primarily I want to encode some plain text Strings so they are not too easy to read, and compression would be a nice feature here.
    I already tried the util.zip package, but that one seems to need streams, I simply need Strings.
    Any ideas ??
    thx
    Skippy

    It does not do any compression, in fact it does
    expansion to better encrypt the string (about 50%).How does that work? You want encryption to
    decrease entropy.Why in the world do you say that, pjt33? What a very odd statement indeed. I sure hope you don't work in security, or I do hope you work in security if I'm a bad guy, or a competitor.
    Let's say you had a 6-character string you wanted to encrypt.
    Well, if you didn't increase the entropy, any 6-character plaintext string would have a 6-character encoded equivalent. And if you decreased entropy (e.g. coding the most commonly used words to shorter strings,) it gets even easier to decrypt.
    Presumably there would be no hash collisions, after all, you want this to be reversible.
    Hash collisions decrease entropy too, and, by doing so, make it easier to find a plaintext string that happens to hash to a certain value. This is a Bad Thing.
    Now, to decode this, the Bad Guy only has to consider the set of 6-character strings and their hash values. You could even precalculate all of the common dictionary words, and everything with common letters and punctuation, making decryption virtually instantaneous. Especially if you had decreased the entropy in the signal, making fewer things I had to try.
    But somebody who increased the entropy of their signal by adding random bits and increasing the encrypted size of the message to, say, 64 characters, would make it a lot harder to decrypt.
    The ideal encryption system is pure noise; pure randomized entropy. An indecipherable wall of 0 and 1 seemingly generated at random. Statistical methods can't be used against it; nothing can be deciphered from it; it's as decipherable and meaningless as radio hiss. Now that's encryption!

  • Write a simple string to a file.

    I have a string that is formatted with new lines that I want to write to a file as is. I have not been able to create a File Partner Link that can successfully write the content.
    The opaque approach creates an empty file.
    I have tried defining a new schema as a string, a delimited and a fixed length and the closest I have come is getting the last line written with fixed length.
    This is the input schema. I want to write the file element. The complex_child element contains values I would use to build the file name.
    <xs:complexType name="complex_parent_type">
    <xs:sequence>
    <xs:element name="complex_child" type="ns1:complex_child_type"/>
    <xs:element name="file" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    Anybody have any success? I would think this should be a simple process. We would prefer not to use embedded Java.
    Thanks,
    Wes.

    Hi Wes,
    You could try using this schema:
    <?xml version="1.0" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
    targetNamespace="..."
    xmlns:tns="..."
    elementFormDefault="qualified" attributeFormDefault="unqualified"
    nxsd:encoding="US-ASCII" nxsd:stream="chars"
    nxsd:version="NXSD" >
    <xsd:element name="file" type="xsd:string" nxsd:style="terminated"
                                  nxsd:terminatedBy="${eof}">
    </xsd:element>
    </xsd:schema>
    You could copy over the contents of the string that you want to write out into the element above and then use the "invoke" on a file adapter PL to write it out.
    Regards,
    Narayanan

  • Best Way to Draw A Simple Isoceles Triangle, and Fill it.

    Hi,
    What I assume is a relativly simple problem, ive got the coordinates of the bottom two points of an isoceles triangle, and the height, and need to draw it in Java2D. It's base will always be parrellel to the bottom of the screen.
    I also need to be able to fill or not fill it very simple, what would be the best way to do this?
    Thanks for your time,
    atreides7887

    Create your triangle as an instance of [java.awt.Polygon|http://java.sun.com/javase/6/docs/api/java/awt/Polygon.html] and call [java.awt.Graphics2D.fill(Shape s)|http://java.sun.com/javase/6/docs/api/java/awt/Graphics2D.html#fill(java.awt.Shape)] to paint the triangle to a BufferedImage or in a paintComponent override.
    Read the other methods of Graphics2D for the rest of your answer.
    db

  • Drawing a color string with swing and Graphics2D

    hi guys,
    I am trying to draw a string on a JPanel, and can do so successfully with plain boring text using drawString(string, int, int). How can I change the font and color? Thanks!

    Read the API for java.awt.Graphics.
    db

  • Simple string / bytes problem

    Hi
    I'm basically trying to simulate DES in java from scratch (so no use of existing API's or anything). I've got a basic idea of how DES works (use of a feistel cipher).
    So to start off I'm trying to get the bytes of a string with this simple program:
    public class Test {
         public static void main(String[] args) {     
              String testString = "hello";
              System.out.println(testString.getBytes());
    }The output consists of some characters (namely numbers, letters and 1 special character).
    But when I change the variable testString to some other String, complie and run I still get the same output even though the String is different. Also why are there 9 characters for a String thats only 5 characters long?
    Thanks

    When you use System.out.println( something ) it uses to the toString() method of the object referenced by 'something'. When the something is an array such as an array of bytes the toString() methed returns a pseudo reference to the array which in no way reflects the content of the array.
    If you just want to see the content of the array then use Arrays.toString(something) to generate a String representation of the content of the array.
    Also, the use of String.getBytes() will convert the String to bytes using your default character encoding. This is rarely what you want since the result may depend on which platform you are working on. In my view, the safest and best approach is to explicitly define the encoding and since it will encode ALL characters one can throw at it I always use utf-8. So, to convert a String to bytes I would usebyte[] bytesOfString = "your string".getBytes("utf-8");and to convert them back to a String I would useString yourString = new String(bytesOfString,"utf-8");One final point, do not assume that an apparently random array of bytes such as one gets from DES encryption can be converted to a String using the above. In general it can't because not all bytes and byte sequences are valid for a particular character encoding. If you absolutely have to have a String representation then you should encode (not encrypt) the bytes using something like Base64 or Hex encoding.
    Edited by: sabre150 on Jan 27, 2008 3:04 PM

  • How to draw a vertical string?

    I use Graphics2D to draw a 2D graph with x-axis and y-axis. I would like to put the name of the y-axis vertically along the y-axis. This means I need to rotate my drawString 90 degrees. How can we do that? I would be very thankful if anyone can help me out.
    Thank you

    I had the same problem when I started developing JFreeChart:
    http://www.object-refinery.com/jfreechart/index.html
    Here is the code I use:
         * A utility method for drawing rotated text.
         * <P>
         * A common rotation is -Math.PI/2 which draws text 'vertically' (with the top of the
         * characters on the left).
         * @param text The text.
         * @param g2 The graphics device.
         * @param x The x-coordinate.
         * @param y The y-coordinate.
         * @param rotation The clockwise rotation (in radians).
        public static void drawRotatedString(String text, Graphics2D g2,
                                             float x, float y, double rotation) {
            AffineTransform saved = g2.getTransform();
            AffineTransform rotate = AffineTransform.getRotateInstance(rotation, x, y);
            g2.transform(rotate);
            g2.drawString(text, x, y);
            g2.setTransform(saved);
        }Regards,
    Dave Gilbert
    JFreeChart Project Leader

  • How to draw a simple little line.

    I have a JApplet that loads images from a jar file. This applet can scale the images, and move them left right, up and down.
    I just want to be able to draw a line on top of the images and then erase it if needed. How do I do this?
    Currently, I have a the jpg images loaded into an Image, which is then converted to an ImageIcon, which is then used to create a JLabel, which is used to create a JScrollPane which finally gets added as a tab on a JTabbedPane.
    I was told to use BufferedImage but that didn't help me. Here is what I have currently:
    private void draw()
    //Get the current image to draw on
    JScrollPane jsp = (JScrollPane)m_tabbedPane.getSelectedComponent();
    JViewport port = jsp.getViewport();
    GrabAndScrollLabel gnsLabel = (GrabAndScrollLabel) port.getView();
    ImageIcon ii = (ImageIcon) gnsLabel.getIcon();
    BufferedImage bi = new BufferedImage (ii.getIconWidth(),
    ii.getIconHeight(),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.setPaint(Color.blue);
    g2.drawLineRect(100, 200, 300, 500);
    g2.drawImage(ii.getImage(),null,null);
    ImageIcon newIcon = new ImageIcon(ii.getImage());
    gnsLabel.setIcon(newIcon);
    port.setView(gnsLabel);
    jsp.setViewport(port);
    getRootPane().revalidate();
    getRootPane().repaint();
    Please help. I can't believe it has to be this difficult to draw a little line.
    Thanks.

    I have a little more insight into my problem.
    I built a sample form Sun (the Map_Line sample). It looks like this:
    public class Map_Line extends Applet
    private BufferedImage bi;
    public Map_Line()
    setBackground(Color.white);
    Image img = getToolkit().getImage("bld.jpg");
    try
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(img, 0);
    tracker.waitForID(0);
    catch (Exception e)
    int iw = img.getWidth(this);
    int ih = img.getHeight(this);
    bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bi.createGraphics();
    big.drawImage(img, 0, 0, this);
    public void paint(Graphics g)
    Graphics2D g2 = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;
    int bw = bi.getWidth(this);
    int bh = bi.getHeight(this);
    g2.drawImage(bi, null, 0, 0);
    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(5.0f));
    g2.drawLine(10, 10, bw - 10, bh - 10);
    public static void main(String[] s)
    WindowListener l = new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    Frame f = new Frame("Map_Line");
    f.addWindowListener(l);
    f.add("Center", new Map_Line());
    f.pack();
    f.setSize(new Dimension(350, 250));
    f.show();
    Note how the drawing is done in paint. This applet works just fine for me.
    The difference is that I'm trying to use the BufferedImage to get my Graphics2D object where as this one gets it from paint (casts Graphics to Graphics2D).
    This applet works just fine, but if you try to use the Graphics2D that comes back from the BufferedImage, it doesn't work!.
    For example, if I create a member variable:
    Graphics2D big;
    And then in paint do this:
    //Graphics2D g2 = (Graphics2D) g;
    Grahics2D g2 = big;
    It no longer works!
    So, it looks like I need to use something other than the
    BufferedImage.createGraphics() to get the Graphics2D object I need.
    Does this seem right?
    Thanks!

  • Drawing a simple envelope

    In CS5, I want to make a simple envelope icon. I draw a rectangle, and then I want to add anchor points to it using the Add Anchor Point Tool, though I am not quite sure what I am doing wrong. Sometimes I am able to add anchor points to the rectangle, and other times I get an error message. When I was able to add the anchor point, I added it to the top center and then I used the Direct Selection Tool to drag that anchor point down to make the flap, though by doing this I lost the top part of my envelop. What is the right way to do this?
    Thanks!

    Draw two paths; one rectangle (which you have) and one triangle for the flap. You actually don’t need a triangle. Just use the pen tool and click three times: Top left corner, centre, top right corner. Make sure the rectangle is not selected first.

  • Simple String Encryption

    HI,
    I have been serching around on here for encyption methods but there seems to be soo many i not sure which ones would be good for me.
    All i want to do is encypt and decrypt a String record. The encryption doesnt have to be particulary safe but must work for all possible charaters. Basically i am saving records to a text file and i dont want someone to be able to open the text file and read the contents.
    I would like to make it as simple as possible so i can just use it like:
    String record = "This is the record";
    // Encrypted Record
    String encRecord = Encryption.encrypt(record);
    // Decripted Record
    String decRecord = Encryption.decrypt(record);Can anyone stear me in the right direction or give me some sample code i can study.
    Thank you in advance
    ed

    Here is simple encryption routine that I just wrote that I bet would keep someone
    stumped for a while.
    * This is a simple encryption class that uses simple character substitution.
    * To keep the pattern from being obvious the shift factor is a function of the current character's
    * position in the source string. This makes sure that all letters aren't encrypted to the same value.
    * Usage: To encrypt a string just pass it to the encrypt method.
    *         String encryptedString = Encryptor.encrypt("Some string.");
    *        To decrypt a string just pass the encrypted string to the decrypt method.
    *         String decryptedString = Encryptor.decrypt(encryptedString);
    class Encryptor
      static final byte [] shiftFactor = {2,5,7,9,13,17,19};
      static final int modulo = shiftFactor.length;
      static public String encrypt(String s)
         char [] ba = s.toCharArray();
         for (int i = 0; i < ba.length; i++)
              ba[i] += shiftFactor[i%modulo];
        return new String(ba);
      static public String decrypt(String s)
         char [] ba = s.toCharArray();
         for (int i = 0; i < ba.length; i++)
              ba[i] -= shiftFactor[i%modulo];
         return new String(ba);
      public static void main(String [] args)
         String [] test = {"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz,./<>?;':\"[]{}-=_+!@#$%^&*()`~",
                           "Now is the time for all good men \n to come to the aid of their country."};
        for (int i = 0; i < test.length; i++)
              System.out.println(test);
              String encrypted = Encryptor.encrypt(test[i]);
              System.out.println(encrypted);
              System.out.println(Encryptor.decrypt(encrypted) + "\n");

  • How to draw a simple line chart using GRAPH_MATRIX_2D function

    Hello,
    can anyone help me with that function please,
    i couldn't draw a line graph with three data series, i mean with three lines in the graph.
    i want to the chart to be drawn as line graph at the beginning, i shouldn't have to change the chart type later,
    can anybody send me a sample code that does what i want.
    i am expecting your answers,
    thanks.
    Note: all answers will be pointed.

    Hi Ali,
    please refer to my reply [here|Re: drawing 2d line chart problem, urgent please!!!] and skip this thread. This is a copy of the other request.
    Regards
    Matthias

  • Is there an easy way to draw a simple parallogram. . . CS 3

    I'm blind I guess, I can't find it... Thanks!! L W - Also fill with color...

    Draw a rectangle with the rectangle frame tool. While still selected, go to the Transform panel to find the Shear field and type in an angle.
    Mike Witherell in Maryland

  • DB Adapter 902 binding exception while passing parameters for simple string

    Hi,
    I have an PlSQL API with two input paramters of string type... But this is only started after XML validation TRUE on the BPM server.
    The error is
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="code"><code>902</code>
    </part><part name="detail"><detail>
    Internal Exception: java.sql.SQLException: ORA-00902: invalid datatype
    Error Code: 902</detail>
    </part><part name="summary"><summary>file:/oracle/product/10.1.3/soa/bpel/domains/Website/tmp/.bpel_BPELProcess1_1.0_c64929dfd2dacf95db3c9da081c1797d.tmp/callingAPI.wsdl [ callingAPI_ptt::callingAPI(InputParameters,OutputParameters) ] - WSIF JCA Execute of operation 'callingAPI' failed due to: Error while trying to prepare and execute an API.
    An error occurred while preparing and executing the XXRBA.XXRBA_WEB_ADAPTER.FETCH_CUSTOMERS API. Cause: java.sql.SQLException: ORA-00902: invalid datatype
    [Caused by: ORA-00902: invalid datatype
    ; nested exception is:
         ORABPEL-11811
    Error while trying to prepare and execute an API.
    An error occurred while preparing and executing the XXRBA.XXRBA_WEB_ADAPTER.FETCH_CUSTOMERS API. Cause: java.sql.SQLException: ORA-00902: invalid datatype
    [Caused by: ORA-00902: invalid datatype
    Check to ensure that the API is defined in the database and that the parameters match the signature of the API. Contact oracle support if error is not fixable.
    </summary>
    </part></bindingFault>
    The input XSD parameters in BPEL input
    <element name="input" type="string"/>
    The input XSD parameters in ADAPTER
    <element name="P_WEB_ACCOUNT" type="string" db:index="1" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    <element name="P_SOLICITED_ONLY" type="string" db:index="2" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    The assignment I am doing in the .bple file is
    <assign name="Assign_1">
    <copy>
    <from expression="bpws:getVariableData('inputVariable','payload','/client:BPELProcess1ProcessRequest/client:input')"/>
    <to variable="Invoke_1_callingAPI_InputVariable" part="InputParameters"
    query="/ns2:InputParameters/ns2:P_WEB_ACCOUNT"/>
    </copy>
    <copy>
    <from expression="string('o')"/>
    <to variable="Invoke_1_callingAPI_InputVariable" part="InputParameters"
    query="/ns2:InputParameters/ns2:P_SOLICITED_ONLY"/>
    </copy>
    </assign>
    --Khaleel                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You have an attribute type in an object service that is supposed to be numeric, but when reading form the database it seems that is retrieving a non-numeric content...
    Cheers,
    Vlad

  • UTF-8 working in JSP not in JavaBean (when assigned to a simple String)

    I am struggling with for last few hours. All I am doing is
    public class Text extends Object implements Serializable {
    public static Hashtable ht = new Hashtable();
    public static void initL10N(){
    public static String xyz = "&#2310;&#2346;&#2325;&#2375;";
    ht.put("hindi",xyz);
    in a JavaBean and trying to access the string in a Jsp Out.jsp as <%=Text.ht.get("hindi")%> I am getting Junk characters.
    But to my surprise: If I do that in a jsp: as (since I declared the ht as public static it's accessable to the new JSP called L10NInit.jsp
    <%
    Text.ht.put("hindi2","&#2310;&#2346;&#2325;&#2375;")l
    %>
    and execute the Out.jsp and then execute my orginal jsp to get the string as <%=Text.ht.get("hindi2")%> it displays beautifully.
    I tried every thing else before turning to this forum. Please help.
    Environment: NetBeans5.5

    In the JSP also I am assigining straignt hindi chars (some how forum displayed entities) as &#2357;&#2376;&#2358;&#2381;&#2357;&#2367;&#2325;

Maybe you are looking for

  • No data in webby using IE or firefox but data in webby Rich client

    hi everybody, I got a newbie probleme with BO edge XI r3.1 trial version. If i create a report on webby via infoview usin a webby universe (efashion eg) , no text appear in my report, inluding data and text titles even i type something (structure is

  • Creating a year planner issue

    Hey I'm trying to set up a year planner to keep track of lessons ill be teaching. I used the 'Fill Down' fucntion to write all the days in a column going down, but when it comes to doing the same with the date, for some reason now all it does is repe

  • Laptop Functionality in GNOME

    I have a Toshiba Sattelite-L305. I have installed Arch Linux, laptop-mode tools and gnome-power-manager on it. GNOME gives me no functionality for changing brightness and does not dim when power is out. Why?

  • Data source issue in RSA7???? urgent plz

    hi experts, unfortunately i have deleted my data source from RSA7, i want to extract new records and push to BI. but its deleted. what is the procedure to make my data source available... my update method is QUEUED DELTA.. plz provide me the solution

  • BADI for Reservation Creation in Extended Classic

    Dear SRM Gurus, System: SRM Server 5.5 Technical Scenario: Extended Classic. We have requirement to create RESERVATION if stock exist for that particular item, and not based on product category , in R/3. I need help as to which BADI is to be used ? W