Newbie String Question

* @(#)NumberBox.java 1.0 03/11/03
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.util.*;
public class NumberBox extends JApplet
                         implements ActionListener{
     JButton medianButton;
     JButton avgHighLowButton;     
     JTextField inputNumbers;
     ArrayList userInput;
     public void init() {
          Container c = getContentPane();
          inputNumbers = new JTextField(100);
          avgHighLowButton = new JButton ("List Details");
          medianButton = new JButton("Get Median");
          userInput = new ArrayList();
          c.add(avgHighLowButton);
          c.add(medianButton);
          c.add(inputNumbers);          
          getContentPane().setLayout(null);
          inputNumbers.setBounds(150,50,300,30);
          avgHighLowButton.setBounds(390,260,100,30);
          avgHighLowButton.addActionListener(this);
          avgHighLowButton.setActionCommand("avg");
          medianButton.setBounds(10,260,100,30);
          medianButton.addActionListener(this);
          medianButton.setActionCommand("median");
     public void actionPerformed (ActionEvent e){
     if ("median".equals(e.getActionCommand()))
System.out.println("median pressed");
JOptionPane.showMessageDialog(null, "The Median of this Set is: \n");
else
          System.out.println("avg pressed");
          JOptionPane.showMessageDialog(null, "The Average of this Set is: \nThe Highest Number is: \nThe Lowest Number is: \n");
     public void ActionPerformed (ActionEvent e){
     //String = string;
          JOptionPane.showInputDialog(null,inputNumbers.getText());
          //string = " " + inputNumbers;
          //System.out.println("User Input"+ string);
basically i want the user to type in a comma seperated list of numbers into a JtextField and tokenise this for manipulation. what i don't really know (and can't seem to find a simple answer too) is how to convert this input text into a String in the first place. either my basic understanding of the language is skewed (very likely) or i'm missing something very simple (also very likely).
any suggestions, other than STFW. java.sun/google is good and all but as stated i can't seem to find a simple answer.

yeah, but my problem is that i don't know how to do
any sort of manipulation. say i wanted to trim the
string, String inputNumbers = inputNumbers.trim()
doesn't work. what i actually want to know is how to
access the string.
If you look at the API documentation for JTextField, you will see that JTextField inherits the method getText() from JTextComponent. getText() returns a String representation of the characters entered in the JTextComponent.String inputstring = inputNumbers.getText(); //get text into a String
inputstring = inputstring.trim(); //for example

Similar Messages

  • General place for newbie datamodeler questions?

    With the production release of SQL Developer Data Modeler I'd assume that this forum will draw a bunch of new users. Is there a better place to ask some pretty simple, newbie like questions that won't bother the more seasoned members?
    For instance, I am working in a Rails environment, which has some stringent naming conventions, one of which is that all of the primary key columns are numeric and called "id", with the foreign key linked columns called <table_name>_id.  When engineering a logical model to a relational model, the added foreign key columns are all "id#".  Is there a way I can define a naming rule to keep me from having to redo the relation column names?
    Also, we have a standard set of columns (mostly Rails related) which appear in every table. Can I define a generation rule which automatically includes these tables?
    Thanks

    Thank you. I will try changing that setting.
    IS there a setting which tells the relational model to automatically create pk and fk indexes? I haven't seen one, and manually setting them up is a tedious task. --sw                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Newbie script question... consecutive numbers with update.

    complete newbie type question... this is also my first post.  ( I am using CS3)
    does anyone have a script which can make it so I can add numbers into the text consecutively.
    for example, if this is my text "the big fat dog sat on the very wide mat, but was then displaced by a unfriendly cat."
    and I wanted to place a number 1, number 2, 3, etc at points in the text so it read, "the big fat dog1 sat on the very wide mat2, but was then displaced by a unfriendly cat3." but later wanted to add another number and have later numbers update themselves, so the text then said, "the big fat dog1 sat on the very wide mat2, but was then displaced3 by a unfriendly cat.4".
    by inserting the three, the previous three became four.
    Has anyone got something which might be useful in this regard.
    Many thanks
    Steve

    i wanted to avoid footnotes as they leave a bar at the bottom of each page.
    i wanted a script to do something similar to footnotes but not much further.
    does anyone have just a simple script that can do what I asked?
    Steve

  • Newbie XSan question - authenticating a computer from XSan Admin

    Hello - I have a very newbie XSan question!
    I have 2 computers that connect to an XSan. 1 I am having no problems with. The other I am unable to connect with.
    When I look in XSan Admin the 2nd computer (the one that is not working) is not authenticated.
    So I click on it and choose Authenticate. I enter what I know is an Admin username and password for the computer I am attempting to connect. The dot next to the computers IP turns green with 3 dots in it and then it turns gray again. It just does not connect.
    What is the problem?
    Is it licensing?
    Thanks
    Taj

    You need a different license ID for each machine, plus the admin machine. Do you have that?

  • This Newbie Has Questions

    Hi there. I am a newbie to Apple. I purchased the iBook last month and of course, when the MacBook (which had the features I wanted) came out, I rushed out and got one and I'm very pleased with my purchase - but I have a few "newbie" questions:
    1) Printing on a PC based Linksys seems to be a nightmare. I can't get anything printed on the shared HP 2600N and HP1012 printers. I literally have to disconnect them from the PC and plug the USB directly to my MacBook to print. It seems like there should be a better, easier and MacFriendly way of doing this - anyone have an easy solution?
    2) I'm going to purchase Windows XP so I can run my windows programs on this computer. Does anyone have any pre-installation advice?
    3) I have a blackberry device that worked fine with my iBook, but does not work with my MacBook - any suggestions or is there a software compatibility patch?
    4) I transferred everything from my old Mac to my new Mac with no problem. How can I migrate my contacts from Entourage to the Address Book?
    5) I notice that sometimes the MacBook "stalls" or doesn't work fast in some functions...is it just me - I expect the machine to jump quickly...but sometimes I get that annoying pinwheel when opening programs.
    Thanks for your help!

    1) Printing on a PC based Linksys seems to be a
    nightmare. I can't get anything printed on the
    shared HP 2600N and HP1012 printers. I literally
    have to disconnect them from the PC and plug the USB
    directly to my MacBook to print. It seems like
    there should be a better, easier and MacFriendly way
    of doing this - anyone have an easy solution?
    The problem is probably a driver issue.
    Printing to a printer on a XP PC from a Mac running 10.4.x
    http://www.ifelix.co.uk/tech/3015.html
    You may need to use a third-party driver such as the HPIJS drivers or the Gimp-Print drivers, but this is not the case with all printers.
    2) I'm going to purchase Windows XP so I can run my
    windows programs on this computer. Does anyone have
    any pre-installation advice?
    Ensure you get a full version (not an upgrade version) and it comes with XP SP2 already.
    Do not install Boot Camp on a critical machine and make regular backups of your data, this is beta software and there are bugs and issues.
    5) I notice that sometimes the MacBook "stalls" or
    doesn't work fast in some functions...is it just me -
    I expect the machine to jump quickly...but sometimes
    I get that annoying pinwheel when opening programs.
    Are these Universal or PPC only applications?
    iFelix

  • A few basic string Questions

    I would like to know how to make a string with the same characters as another string. Also, how can I set an int with the same value as there are characters in a string. It would really help if you gave me an example, because I am new to java and pretty much lost.

    That page has alot of information, but I really don't
    know how to use any of it. It would be really helpful
    is some one gave me an example. I see something like
    "int length ( )", but I don't know how to use it.You don't know how to call a method? Then you need to start from the very beginning:
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.
    Here's a freebie though:String str = ...;
    int len = str.length();

  • Two String questions

    Hi!
    I have two questions:
    1) Can I do toString() on a null value?
    2) Is there any difference in writing:
    String s = new String();
    and
    String s;

    isnt it true that in the first case s -object of
    String class is created??Yes, the empty string, length zero, as he said.
    >
    in second case just defining a variable type String??Yes. It will either be null or have an udefined value, depending on whether it's a member variable or a method variable.

  • Newbie wireless question (slightly off-topic)

    I didn't want to post this here as it's not entirely an Airport-specific question. I posted this to the iBook forums, but nobody there has answered so my apologies if this is not welcome here. (Any moderators can remove it if that's the case.)
    I've been using computers extensively for over a decade, but I'm a total newbie to wifi. I just set up a wireless network in my house and would appreciate some advice/feedback.
    My main concerns are whether or not my network is reasonably secure. I know there is no such thing as perfect security, but I don't know if what I've done is good enough or not.
    I don't have an Airport base station, but I do have a D-Link Airplus G and an Airport card in my iBook. I have WEP set up on the router and I have enabled MAC filtering, listing only my desktop and my iBook, excluding all others from the network.
    I'm fairly certain that nobody in my neighborhood is going to get into my machines this way or be able to sniff my network data stream, but am I right in assuming that nobody can "piggyback" on my Internet connection too? Presumably, if everyone but my own machines are MAC-filtered and kept out, then the Internet connection is also protected. Is that how it works?

    WEP and MAC filtering are better than nothing, but you can do better. These are my suggestions:
    1. Use WPA with a pre-shared key (PSK) and TKIP encryption on your Netgear router, along with an alphanumeric passphrase of at least eight characters not found in any dictionary. The equivalent setting on your Mac is "WPA Personal". Unlike WEP security (which an expert can crack in under half an hour), WPA security is currently unhackable by any practical means as long as you use a non-dictionary passphrase. One last point - WPA security requires all your wireless Macs to be running MacOS 10.3 or newer.
    2. MAC filtering is (these days) essentially useless as a wireless security method. Using "packet sniffing" of traffic on your wireless network to find out what MAC addresses are used by computers on your network, and a PC that allows its MAC address to be cloned so that it is identical to the MAC address of one your own wireless computers (which is possible with most PC wireless network adapters) even an amateur hacker can defeat MAC address filtering in minutes.
    By the way - I don't think your posted message here is off topic. In my opinion, the Airport discussion forums are the best place to post any questions related to usage of wireless networks. Questions of this nature are virtually never specific to any Mac model.

  • Convert string question... "\"

    I try the below code on jsp, but result is : a , a\b
    but I want the result is : a\\b, a\\\\b
    Thanks !
    <%
         String str = "a\b, a\\b";
         String outStr = "";
         for (int i=0;i<str.length();i++){
              char c = str.charAt(i);
              if (c == '\\'){
                   outStr += "\\";
              else{
                   outStr += c;
    %>
    <%=outStr%>

    Right, because the compiler interprets "\\" as an escape character, indicating that you want a backslash. (If you tried to just use a String "\", you'd probably get a compilation error, since the compiler would think you were trying to escape the second quotation).
    I think you're going to need to use RegExp... this question has been asked a bunch before, so search through the forums for an answer.

  • Number - string question

    Hello,
    I have the next problem:
    I have cursor that contains the next thing:
    WHERE LKP_INDUSTRY1_ID IN ( p_sector )
    p_sector is being delivered in varchar: '23;22;36'
    My question is: is it possible to manipulate p_sector in a way that I can paste it in my cursor? I can replace the ';' with ',' but I don't know how I can make it read the numbers as numbers and not as strings.
    Thanks in advance.
    Oli

    Does this solve your problem ?
    SQL> create or replace type tab_n is table of number;
      2  /
    Type created.
    SQL> declare
      2   p_sector varchar2(20) := '7369;7499;7521';
      3   t tab_n := tab_n();
      4   element number;
      5   pos integer := 0;
      6   cursor a is select ename from emp where empno in (select * from table(t));
      7  begin
      8   for i in 1..length(translate(p_sector || ';',';0123456789',';')) loop
      9    t.extend;
    10    t(t.count) := substr(p_sector,pos+1,instr(p_sector || ';',';',1,i)-pos-1);
    11    pos := instr(p_sector,';',1,i);
    12   end loop;
    13   for v in a loop
    14    dbms_output.put_line(v.ename);
    15   end loop;
    16  end;
    17  /
    SMITH
    ALLEN
    WARD
    PL/SQL procedure successfully completed.Rgds.

  • Total newb var question

    Hello :) ,
    so Im a total newb :(
    I am trying to make this code into a function....
    <code>
    jd_label.setIcon(new javax.swing.JLabel(){
    public javax.swing.Icon getIcon(){
    try {
    return new javax.swing.ImageIcon(
    new java.net.URL("http://ns2.taproot.bz/java/prima_interface/thumbs/02.jpg")
    catch (java.net.MalformedURLException e){
    return null;
    }.getIcon());
    </code>
    problem is, Im such a new i dont know how to use a var on this line...
    jd_label.setIcon(new javax.swing.JLabel(){
    I would like jd_label to be a $var but java just wants to update
    a label named "var".... i.e.
    JLabel jd = new Jlabel();
    string fred = jd
    fred.setIcon()
    but this freaks out... in PERL it seems the vars are a little more
    reconazable...
    $fred.setIcon();
    Could some one please help me :)
    Thanks in advance,
    jd

    Thank you :)
    Im still confused...but that will pass in time
    As for the code in the first post... that was from a scrip i wrote
    but the section i posted NetBeans wrote. here is the whole scrip...
    All i really want to do is put pictures on labels...and i thought, why write
    the same code for every button, ill just make a function out of the whole setIcon bit and call it for each label that needs a picture, passing the url of the picture off to the function... Below gets me one pic on one label, so
    how can i reproduce this efffect on other lables using the same code over and over?
    import javax.swing.*;
    import java.awt.*;
    public class HelloWorldSwing {
    public static void main(String[] args) {
    JFrame frame = new JFrame("HelloWorldSwing");
    JLabel label = new JLabel("Hello World");
    JLabel jd_label = new JLabel();
         JTextField tex = new JTextField("sup suka");
         JPanel pan = new JPanel();
         pan.setLayout(new GridLayout(1,3,10,10));
         pan.add(label);
         pan.add(jd_label);
         pan.add(tex);
    // i wanna make this bit into a fuction to reuse
         jd_label.setIcon(new javax.swing.JLabel() {
    public javax.swing.Icon getIcon() {
    try {
    return new javax.swing.ImageIcon(
    new java.net.URL("http://ns2.taproot.bz/java/prima_interface/thumbs/02.jpg")
    } catch (java.net.MalformedURLException e) {
    return null;
    }.getIcon());
         frame.getContentPane().add("Center", pan);
         frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

  • Newbie saving question in Illustrator

    I know this is a newbie question. I designed a logo in Illustrator. Is there a way to save just the logo for exporting into other applications (ie Pagemaker or Photoshop) without having the white artboard?
    Thanks
    Brad

    I don't know Pagemaker but with Photoshop I simply select all, copy and then paste in Photoshop - transparency will be maintained. If you paste as a Smart Object you retain the ability to edit the Illustrator artwork in Illustrator and update the PS file.

  • ITouch Newb with Questions

    Actually, I'm not even a Newb yet...I am planning on getting an iTouch after Xmas (with my expected gift cards ). I have a few concerns that I would love to hear more about if anyone would like to comment:
    1. The 32GB iTouch says it can hold 7000 songs and/or 40 hours of video. How much memory does an average movie take up? For example, Iron Man.
    2. I've been reading the forums to get better acquainted with the iTouch before I get one and there seem to be a lot of recurring issues/bugs: iTunes not recognizing it, some movies not playing, etc. Does this have to do with the 2G iTouch being new and possibly having normal "new tech" bugs? Should I buy one now or wait until these are worked out?
    Or am I worrying over nothing?
    3. If I get my 32GB iTouch in Dec/Jan...will a larger capacity one come out in a couple of months? I see the classic iPod goes up to 120GB.
    Any input would be greatly appreciated. I'm one of those people that researches a product to death before buying it.
    Thanks!

    Answer #1: How long is a piece of string? The amount of space a movie takes up will depend on the running time of the movie, what bitrate you encode it at, yadda yadda yadda. To give you a ballpark figure, I've got 10 videos on my iPod at the moment (7 full length movies, 2 TV shows, and one music video) they're taking up 6.6 gig of space.
    Answer#2: Your doctor only gets to talk to sick people all day. Don't be too put off by all the posts here , this is merely the distillation of the folks having problems. For every one post you read here, there are thousands of people you don't hear from because they're not having problems they need to bring here.
    Answer #3: I left my crystal ball at the office. But having said that, better iPods will come out in the future, thats a given. How long?, at the moment very large capacity Flash RAM is still very pricey stuff, I don't think you'll be seeing 120Gb IPT's any time soon.
    You're not worrying over nothing, you've posted very valid considerations, you just need to look at 'em in context.

  • Newbie forms question

    Hi,
    I'm just experimenting with forms (in the development suite) and I have now created a data block with table data, got it running within a browser and was feeling quite pleased with myself.
    I have now tried to do a similar thing with a stored procedure and I get the error message FRM-10764 no argument of type table or refcursor.
    Now I've done some plsql so I know about ref cursors, I do not however know what a table object is, or more to the point how/why a pl/sql procedure would/could return a table object.
    Can anyone explain this concept of how a procudure returns a table object and why is it that forms will not let me just display a single string or numeric response from a procedure?
    thanks in advance,
    Paul.

    Ed,
    I am newbie myself on Oracle but I think I can help you on this one. Do the following:
    1) Create the buttonl;
    2) Assign a WHEN_BUTTON_PRESSED trigger to that button;
    3) Use the CALL_FORM built-in procedure to call the second form; (look for examples on the help / forms builder help topics, it's a pretty good source of code sample and examples)
    Hope it works out.
    Gleisson

  • Dumb newbie hardware question! :)

    Hi folks,
    I'm new to the world of the blackberry and am just about to take the plunge with an unlocked sim-free BB Bold to use in the UK on Vodafone. I have read about the software differences between BIS and BES and would be going for a BIS set-up. My dumb newbie question is does the hardware come in BES and BIS versions or not?
    Many thanks in advance and feel free to mock my foolishness
    Solved!
    Go to Solution.

    hello, about BIS and BES it's explained on the website but it's clear that if someone sums it up for you it will be easier...
    so BES is a type of contract between a company and Blackberry. The company IT buy computers, put Blackberry servers, and buy a fleet of Blackberry Devices for the people in the company to use them and get email through the Blackberry servers.
    BIS is a type of contract between a common person and a carrier. The consumer goes to the carrier, and buys a Blackberry device, and a BIS plan that will enable him/her to :
    phone/sms/mms
    receive emails that have been configured on the BIS site
    do data things if you subscribe to (like browse the web)
    You can buy a Blackberry from a carrier that has a deal with RIM (the company that sells Blackberries). Or you can buy a blackberry alone, and then go and contact a carrier that has a deal with RIM.
    phone/sms/mms
    receive emails that have been configured on the BIS site
    do data things if you subscribe to (like browse the web)
    The search box on top-right of this page is your true friend, and the public Knowledge Base too:

Maybe you are looking for