Guys I need some help. String token of a wired message

well this is my code.
code:
import java.*;import java.util.StringTokenizer;import java.io.*; class stringtoken {         public static void main(String[] args) {         Runnable daemonRunner = new Runnable()        {                public void run()                        {                         while (true)                                {                    String red, green, blue, yellow, brown, v6, v7;                                        int ali=42;                                         String origtext = "accaa*b*dzddsf*,.sfsdf,a.a/.d,asd.,fa.a/.,/.**asdasdaadf";                                        StringTokenizer st = new StringTokenizer(origtext,"*");                                        try {                                        red = (String)("a" + st.nextToken());                                         green = (String)(st.nextToken());                                        blue = (String)(st.nextToken());                                        yellow = (String)(st.nextToken());                                        brown = (String)(st.nextToken());                                         System.out.println("Red : " + red);                                        System.out.println("Green : "+ green);                                        System.out.println("Red : " + blue);                                        System.out.println("Green : "+ yellow);                                        System.out.println("Blue : " + brown);                                        /////////////////////////////////[shaded section]/////////////////// String red1,red2;int ie=41; String aChar1 = new Character((char)ie).toString(); System.out.println("From above : Red" + red + " *** Will token -> " + aChar1); StringTokenizer st1 = new StringTokenizer(red, ")"); try {                                                red1 = (String)("After splitting 1 :" + st.nextToken());                                                red2 = (String)("After splitting 2 :" + st.nextToken());                                                System.out.println("Output : " + red1 + "&" + red2 );                                                        } catch (Exception ignored) { // (ERROR STATE) could not parse it                                                        } ////////////////////////////////[end of shaded section]/////////////////// int a = 0x41;int i=65; String aChar = new Character((char)i).toString(); System.out.println("Ending : " + aChar); } catch (Exception ignored) { // (ERROR STATE) could not parse it                                        } try {                                                Thread.sleep(1500);                                        } catch (InterruptedException ignored ) {                                        } } } }; Thread daemonThread = new Thread(daemonRunner); daemonThread.setDaemon(false); daemonThread.start(); try {                Thread.sleep(1000);                } catch (InterruptedException ignored) {                } } }
let me explain a lil. The program is actually a daemon. It works fine. In the body run, that's the thingy which did string token. It works fine. But
i am creating something that will split (1a) into 2 piece, and another will spilt the other piece.
The senario, the daemon will receive a string, like "*abcde,1,2,3,hello%"
where * = STX (ASCII 02) and % ETX (ASCII 03)
the first loop will eliminate the STX, then seggregate the text to a loop, for example a=abcde, b=1, c=3, d=hello%.
*what i managed to do is only string token the normal characters, not the ASCII characters 
then the final loop will grab strtoken the % char.
i have been trying tht for 1 whole days.. n e ideas guys ?
thanks in advance.
you could also post the edited text to [email protected]

I have solve the problem. Thanks guys!
import java.*;
import java.util.StringTokenizer;
import java.io.*;
class stringtoken1 {
public static void main(String[] args) {
     Runnable daemonRunner = new Runnable() {
          public void run() {
                    while (true) {
                    int STX=2, ETX=3, comma=44;
                    String stx = new Character((char)STX).toString();
                    String etx = new Character((char)ETX).toString();
                    String flag= null;
                    String ID= null;
                    String date= null;
                    String location= null;
                    String mobile= null;
                    String outtouser= null;
                    String message1=null;
                    String message2=null;
                    String origtext = stx+"1,001,17062005 16:16:16,Rawang, Telekom, Please stand by "+etx;
                    //System.out.println(origtext);
                                        String throwstx = new Character((char)STX).toString();
                                        StringTokenizer stxthrow1 = new StringTokenizer(origtext, throwstx);
                                        try {
                                              message1 = (String)(stxthrow1.nextToken());
                                        catch (Exception ignoredthrowstx) {System.out.println(ignoredthrowstx);}
                                        String throwetx = new Character((char)ETX).toString();
                                        StringTokenizer etxthrow = new StringTokenizer(message1, throwetx);
                                        try {
                                                   message2 = (String)(etxthrow.nextToken());
                                        catch (Exception ignoredthrowstx) {System.out.println(ignoredthrowstx);}
                                        String chomma = new Character((char)comma).toString();
                                        StringTokenizer st = new StringTokenizer(message2,chomma);
                                        try {
                                                  flag = (String)(st.nextToken());
                                                  ID = (String)(st.nextToken());
                                                  date = (String)(st.nextToken());
                                                  location = (String)(st.nextToken());
                                                  mobile = (String)(st.nextToken());
                                                  outtouser = (String)(st.nextToken());
                                        catch (Exception ignoredcomma) {System.out.println(ignoredcomma);}
                                        System.out.println("Original Message : " + origtext);
                                        System.out.println("After STX : " + message1);
                                        System.out.println("After ETX : " + message2);
                                        System.out.println("Filtering");
                                        System.out.println("flag : " + flag);
                                        System.out.println("id : "+ ID);
                                        System.out.println("date : " + date);
                                        System.out.println("location : "+ location);
                                        System.out.println("mobile : " + mobile);
                                        System.out.println("message : " + outtouser);
                         try {
                          Thread.sleep(3000);
                          catch (InterruptedException ignored ) { }
Thread daemonThread = new Thread(daemonRunner); daemonThread.setDaemon(false);
daemonThread.start();
try { Thread.sleep(1000);}
catch (InterruptedException ignored){ }
}for others guys as well :)

Similar Messages

  • HT1338 Guys I need some help with deleting junk mail/bulk mail...I keep getting this air message that says THE IMAP COMMAND "UID COPY" (TO DELETED MESSAGES) FAILED FOR THE MAILBOX "BULK MAIL" WITH SERVER ERROR: UID COPY SERVER ERROR- PLEASE TRY AGAIN LATE

    I need help in deleting my junk mail/bulk mail...when I dump junk mail and bulk mail into the trash it not allowing me to delete all mail only some. HELP!!

    What program are you using?  And what version?

  • Hey Guys, I need some help here

    Im doing some create view and create procedures for my work.
    In creating view, its just done perfectly.
    However with create procedures work, I got some problem with the result.
    So here is the coding:
    create or replace
    PROCEDURE "USP_EDW_CASH_MARGIN"
    result_cursor          OUT     TYPES.cursor_type
    AS
    CURSOR v_cursor IS
    SELECT
    to_char (CM100,'99999999999999.99'),
    to_char (CM101,'99999999999999.99'),
    to_char (CM200,'99999999999999.99'),
    to_char (CM300,'99999999999999.99'),
    to_char (CM301,'99999999999999.99'),
    to_char (CM310,'99999999999999.99'),
    to_char (CM320,'99999999999999.99'),
    to_char (CM400,'99999999999999.99'),
    to_char (CM401,'99999999999999.99'),
    to_char (CM402,'99999999999999.99'),
    to_char (CM500,'99999999999999.99'),
    to_char (CM720,'99999999999999.99'),
    to_char (CM730,'99999999999999.99'),
    to_char (CM740,'99999999999999.99'),
    to_char (CM999,'99999999999999.99')
    FROM VW_CASH_MARGIN a;
    v_id varchar2(100);
    v_row varchar2(4000);
    v_clob CLOB;
    v_buffer varchar2(10000);
    BEGIN
    v_id := 'EDW_CASH_MARGIN';
    DELETE FROM TBL_INTERFACE_DATA WHERE cd = v_id;
    INSERT INTO TBL_INTERFACE_DATA (CD,INT_DATA,DT_CREATED)
    VALUES (v_id,EMPTY_CLOB(),(SELECT CURR_PROC_DATE FROM TBL_PROC_DATE));
    SELECT INT_DATA INTO v_clob
    FROM TBL_INTERFACE_DATA
    WHERE CD = v_id
    FOR UPDATE;
    OPEN v_cursor;
    v_buffer := '';
    dbms_output.put_line(LENGTH(v_buffer));
    LOOP
    FETCH v_cursor INTO v_row;
    EXIT WHEN v_cursor%NOTFOUND;
    if (length(v_buffer) + length(v_row)) < 10000 or v_buffer is null then
    v_buffer := v_buffer || v_row;
    else
    DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_buffer), v_buffer);
    v_buffer := v_row;
    end if;
    END LOOP;
    if LENGTH(v_buffer) > 0 then
    DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_buffer)-1, v_buffer);
    end if;
    CLOSE v_cursor;
    OPEN result_cursor FOR
    SELECT 'success' AS status FROM dual;
    END;
    After i run this coding.
    I got these errors :
    1)Error(46,5): PL/SQL: SQL Statement ignored.
    2)Error(46,5): PLS-00394: wrong number of values in the INTO list of a FETCH statement
    It says that the error is with this code "FETCH v_cursor INTO v_row;"
    Can someone please help me.

    ok let me explain with emp table.
    DECLARE
    CURSOR c IS SELECT ename,sal FROM emp;
    v_ename VARCHAR2(2000);
    BEGIN
    OPEN c;
    LOOP
    FETCH c INTO v_ename;
    EXIT WHEN c%NOTFOUND;
    Dbms_Output.put_line(v_name);
    END LOOP;
    CLOSE c;
    END;Here i'm selecting 2 columns in the cursor and getting into one variable.
    So i'm getting error like this
    ORA-06550: line 7, column 1:
    PLS-00394: wrong number of values in the INTO list of a FETCH statement
    ORA-06550: line 7, column 1:
    PL/SQL: SQL Statement ignored
    DECLARE
    CURSOR c IS SELECT ename,sal FROM emp;
    v_ename VARCHAR2(2000);
    v_sal NUMBER(10);
    BEGIN
    OPEN c;
    LOOP
    FETCH c INTO v_ename,v_sal;
    EXIT WHEN c%NOTFOUND;
    Dbms_Output.put_line(v_ename||v_sal);
    END LOOP;
    CLOSE c;
    END;Here i'm selecting 2 columns in the cursor and getting into two different variables.so no error.
    DECLARE
    CURSOR c IS SELECT ename,sal FROM emp;
    v_row c%rowtype; -->record type declaration
    BEGIN
    OPEN c;
    LOOP
    FETCH c INTO v_row;
    EXIT WHEN c%NOTFOUND;
    Dbms_Output.put_line(v_row.ename||v_row.sal);---> Here i'm mentioning which column to be printed
    END LOOP;
    CLOSE c;
    END;Same thing i'm getting all columns variable into the records so no error.
    and also pls read this
    How to ask question
    SQL and PL/SQL FAQ

  • Alright guys I need some help here with itunes and my music files

         Basically, I've had two apple accounts in the past like 4 years.  One day I connect my Ipod touch to my computer and downloaded an update from Itunes, not knowing that it erases all your content.  I didnt have my music files backed up either, so I ended up losing over $300 worth of music and apps.  Ever since then I never updated my touch, from the fear of losing my music.  Now that I have my own apple account, I have music files from the first account and my account.  My question is how can I back both of these groups of files up and update my ipod without losing any of this content!?  I would really appreciate a step by step process etc.  Thanks guys for helping me out!
    -Colin Wagner

    You can always redownload iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    You can transfer iTunes purchases to your computer by:
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer

  • Guys i need some help

    hai guys, i have a problem with my bills payment regarding about mac os x lion. I bought my macbook pro at 27th of july and i already registered and make sure that i dont pay for the lion, and i already receive the email saying my bill is free, but then the next day i receive another email saying that i have to pay for it, well i know i already know that it might be imposible for me to refund, but at least i want to know whats the problem, because i already register my macbook pro so i dont need to pay for the OS. thanks

    Hi a,
    We are not Apple and have no access to their records. Please contact Apple directly to ask this question.

  • Hey guys i need some help!!!

    I have a slow iMovie4 but only when I am in timeline view.

    sometimes, when a project gets a degree of 'complexity' it could start to behave odd...
    how long is your project?
    have you done 'zillions of trial & error edits'?
    is it possible for your workflow, to export the whole project to tape, and re-import into a new iM project (=no quality loss...)? that 'consolidates' the internal files of a iM project and it is a 'fresh' start...
    and set iM's prefs for Playback to 'Standard' ....

  • My iPhone 3g has 2 white horizontal lines i don't know where did it came from. I turn it off then on but its still there. the lines spreads everyday. I dont know how to fix it. need some help guys.

    my iPhone 3g has 2 white horizontal lines i don't know where did it came from. I turn it off then on but its still there. the lines spreads everyday. I dont know how to fix it. need some help guys.

    If you take a screenshot (Press the home button and Lock button at the same time), does it appear on the screenshot? Zoom in on the screenshot and see if it's still there.
    If not, then your display is failing. I would recommend taking it to an Apple Store if you can, if you can't then to an authorised Apple reseller.
    If it does appear on the screenshot when you zoom into the spot, then it's a really weird software issue! You might have to backup and restore the device.
    Let me know!
    xeni

  • Need some help in creating Search Help for standard screen/field

    I need some help in adding a search-help to a standard screen-field.
    Transaction Code - PP01,
    Plan Version - Current Plan (PLVAR = '01'),
    Object Type - Position ( OTYPE = 'S'),
    Click on Infotype Name - Object ( Infotype 1000) and Create.
    I need to add search help to fields Object Abbr (P1000-SHORT) / Object Name (P1000-STEXT).
    I want to create one custom table with fields, Position Abb, Position Name, Job. Position Abb should be Primary Key. And when object type is Position (S), I should be able to press F4 for Object Abb/Object Name fields and should return Position Abbr and Position Name.
    I specify again, I have to add a new search help to standard screen/field and not to enhance it.
    This is HR specific transaction. If someone has done similar thing with some other transation, please let me know.
    There is no existing search help for these fields. If sm1 ever tried or has an idea how to add new search help to a standard screen/field.
    It's urgent.
    Thanks in advace. Suitable answers will be rewarded

    Hi Pradeep,
    Please have a look into the below site which might be useful
    Enhancing a Standard Search Help
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/daeda0d7-0701-0010-8caa-
    edc983384237
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21ee93446011d189700000e8322d00/frameset.htm
    A search help exit is a function module for making the input help process described by the search help more flexible than possible with the standard version.
    This function module must have the same interface as function module F4IF_SHLP_EXIT_EXAMPLE. The search help exit may also have further optional parameters (in particular any EXPORTING parameters).
    A search help exit is called at certain timepoints in the input help process.
    Note: The source text and long documentation of the above-specified function module (including the long documentation about the parameters) contain information about using search help exits.
    Function modules are provided in the function library for operations that are frequently executed in search help exits. The names of these function modules begin with the prefix F4UT_. These function modules can either be used directly as search help exits or used within other search help exits. You can find precise instructions for use in the long documentation for the corresponding function module.
    During the input help process, a number of timepoints are defined that each define the beginning of an important operation of the input help process.
    If the input help process is defined with a search help having a search help exit, this search help exit is called at each of these timepoints. If required, the search help exit can also influence the process and even determine that the process should be continued at a different timepoint.
    timepoints
    The following timepoints are defined:
    1. SELONE
    Call before selecting an elementary search help. The possible elementary search helps are already in SHLP_TAB. This timepoint can be used in a search help exit of a collective search help to restrict the selection possibilities for the elementary search helps.
    Entries that are deleted from SHLP_TAB in this step are not offered in the elementary search help selection. If there is only one entry remaining in SHLP_TAB, the dialog box for selecting elementary search helps is skipped. You may not change the next timepoint.
    The timepoint is not accessed again if another elementary search help is to be selected during the dialog.
    2. PRESEL1
    After selecting an elementary search help. Table INTERFACE has not yet been copied to table SELOPT at this timepoint in the definition of the search help (type SHLP_DESCR_T). This means that you can still influence the attachment of the search help to the screen here. (Table INTERFACE contains the information about how the search help parameters are related to the screen fields).
    3. PRESEL
    Before sending the dialog box for restricting values. This timepoint is suitable for predefining the value restriction or for completely suppressing or copying the dialog.
    4. SELECT
    Before selecting the values. If you do not want the default selection, you should copy this timepoint with a search help exit. DISP should be set as the next timepoint.
    5. DISP
    Before displaying the hit list. This timepoint is suitable for restricting the values to be displayed, e.g. depending on authorizations.
    6. RETURN (usually as return value for the next timepoint)
    The RETURN timepoint should be returned as the next step if a single hit was selected in a search help exit.
    It can make sense to change the F4 flow at this timepoint if control of the process sequence of the Transaction should depend on the selected value (typical example: setting SET/GET parameters). However, you should note that the process will then depend on whether a value was entered manually or with an input help.
    7. RETTOP
    You only go to this timepoint if the input help is controlled by a collective search help. It directly follows the timepoint RETURN. The search help exit of the collective search help, however, is called at timepoint RETTOP.
    8. EXIT (only for return as next timepoint)
    The EXIT timepoint should be returned as the next step if the user had the opportunity to terminate the dialog within the search help exit.
    9. CREATE
    The CREATE timepoint is only accessed if the user selects the function "Create new values". This function is only available if field CUSTTAB of the control string CALLCONTROL was given a value not equal to SPACE earlier on.
    The name of the (customizing) table to be maintained is normally entered there. The next step returned after CREATE should be SELECT so that the newly entered value can be selected and then displayed.
    10. APP1, APP2, APP3
    If further pushbuttons are introduced in the hit list with function module F4UT_LIST_EXIT, these timepoints are introduced. They are accessed when the user presses the corresponding pushbutton.
    Note: If the F4 help is controlled by a collective search help, the search help exit of the collective search help is called at timepoints SELONE and RETTOP. (RETTOP only if the user selects a value.) At all other timepoints the search help exit of the selected elementary search help is called.
    If the F4 help is controlled by an elementary search help, timepoint RETTOP is not executed. The search help exit of the elementary search help is called at timepoint SELONE (at the
    F4IF_SHLP_EXIT_EXAMPLE
    This module has been created as an example for the interface and design of Search help exits in Search help.
    All the interface parameters defined here are mandatory for a function module to be used as a search help exit, because the calling program does not know which parameters are actually used internally.
    A search help exit is called repeatedly in connection with several
    events during the F4 process. The relevant step of the process is passed on in the CALLCONTROL step. If the module is intended to perform only a few modifications before the step, CALLCONTROL-STEP should remain unchanged.
    However, if the step is performed completely by the module, the following step must be returned in CALLCONTROL-STEP.
    The module must react with an immediate EXIT to all steps that it does not know or does not want to handle.
    Hope this info will help you.
    ***Reward points if found useful
    Regards,
    Naresh

  • Need some help...in need of a different way.

    Hi, I'm new to Java and need some help. I have 2 questions that are similar in nature.
    1st Question:
    In a program that I'm writting I have a do-while loop which at the end brings up a dialog box that asks the user to enter '1' for 'Yes' or '2' for 'No' to continue.
    I would rather have the option of having the user enter 'y' or 'Y' for Yes and 'n' or 'N' for No.
    Here is what I have currently:
    int x;
    String data;
    do{
    //Blah blah code
    data = JOptionPane.showInputDialog(null, "Enter 1 for Yes or 2 for No");
    x = Integer.parseInt(data);
    }while(x == 1);
    x++;
    2nd Question:
    In another part of my program I have a Case statement that asks the user to enter a number or a letter from a list of choices. They can enter '2' , 't', or 'T'.
    I would rather have all of this in an if-else chain. Is this possibe? if so, how would I do it.
    Thanks.

    I would rather have the option of having the user enter 'y' or 'Y' for Yes and 'n' or
    'N' for No. You can test the first letter of whatever the user inputs like this:String response = JOptionPane.showInputDialog(null, "Enter (Y)es or (N)o");
    response = response.toLowerCase();
    if(response.startsWith("y")) {
        // the user entered something starting with y
    } else if(response.startsWith("n")) {
        // the user entered something starting with n
    } else {
        // what are you going to do?
    }JOptionPane also has versions that would allow yes/no buttons. Eg, see:
    http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html

  • Please I need some help with a table

    Hi All
    I need some help with a table.
    My table needs to hold prices that the user can update.
    Also has a total of the column.
    my question is if the user adds in a new price how can i pick up the value they have just entered and then add it to the total which will be the last row in the table?
    I have a loop that gets all the values of the column, so I can get the total but it is when the user adds in a new value that I need some help with.
    I have tried using but as I need to set the toal with something like total
        totalTable.setValueAt(total, totalTable.getRowCount()-1,1); I end up with an infinite loop.
    Can any one please advise on some way I can get this to work ?
    Thanks for reading
    Craig

    Hi there camickr
    thanks for the help the other day
    this is my full code....
    package printing;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.DecimalFormat;
    public class tablePanel
        extends JDialog  implements Printable {
      BorderLayout borderLayout1 = new BorderLayout();
      private boolean printing = false;
      private Dialog1 dialog;
      JPanel jPanel = new JPanel();
      JTable table;
      JScrollPane scrollPane1 = new JScrollPane();
      DefaultTableModel model;
      private String[] columnNames = {
      private Object[][] data;
      private String selectTotal;
      private double total;
      public tablePanel(Dialog1 dp) {
        dp = dialog;
        try {
          jbInit();
        catch (Exception exception) {
          exception.printStackTrace();
      public tablePanel() {
        try {
          jbInit();
        catch (Exception exception) {
          exception.printStackTrace();
      private void jbInit() throws Exception {
        jPanel.setLayout(borderLayout1);
        scrollPane1.setBounds(new Rectangle(260, 168, 0, 0));
        this.add(jPanel);
        jPanel.add(scrollPane1, java.awt.BorderLayout.CENTER);
        scrollPane1.getViewport().add(table);
        jPanel.setOpaque(true);
        newTable();
        addToModel();
        addRows();
        setTotal();
    public static void main(String[] args) {
      tablePanel tablePanel = new  tablePanel();
      tablePanel.pack();
      tablePanel.setVisible(true);
    public void setTotal() {
      total = 0;
      int i = table.getRowCount();
      for (i = 0; i < table.getRowCount(); i++) {
        String name = (String) table.getValueAt(i, 1);
        if (!"".equals(name)) {
          if (i != table.getRowCount() - 1) {
            double dt = Double.parseDouble(name);
            total = total + dt;
      String str = Double.toString(total);
      table.setValueAt(str, table.getRowCount() - 1, 1);
      super.repaint();
      public void newTable() {
        model = new DefaultTableModel(data, columnNames) {
        table = new JTable() {
          public Component prepareRenderer(TableCellRenderer renderer,
                                           int row, int col) {
            Component c = super.prepareRenderer(renderer, row, col);
            if (printing) {
              c.setBackground(getBackground());
            else {
              if (row % 2 == 1 && !isCellSelected(row, col)) {
                c.setBackground(getBackground());
              else {
                c.setBackground(new Color(227, 239, 250));
              if (isCellSelected(row, col)) {
                c.setBackground(new Color(190, 220, 250));
            return c;
        table.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
            if (e.getClickCount() == 1) {
              if (table.getSelectedColumn() == 1) {
       table.setTableHeader(null);
        table.setModel(model);
        scrollPane1.getViewport().add(table);
        table.getColumnModel().getColumn(1).setCellRenderer(new TableRenderDollar());
      public void addToModel() {
        Object[] data = {
            "Price", "5800"};
        model.addRow(data);
      public void addRows() {
        int rows = 20;
        for (int i = 0; i < rows; i++) {
          Object[] data = {
          model.addRow(data);
      public void printOut() {
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(tablePanel.this);
        pj.printDialog();
        try {
          pj.print();
        catch (Exception PrintException) {}
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.black);
        int fontHeight = g2.getFontMetrics().getHeight();
        int fontDesent = g2.getFontMetrics().getDescent();
        //leave room for page number
        double pageHeight = pageFormat.getImageableHeight() - fontHeight;
        double pageWidth =  pageFormat.getImageableWidth();
        double tableWidth = (double) table.getColumnModel().getTotalColumnWidth();
        double scale = 1;
        if (tableWidth >= pageWidth) {
          scale = pageWidth / tableWidth;
        double headerHeightOnPage = 16.0;
        //double headerHeightOnPage = table.getTableHeader().getHeight() * scale;
        //System.out.println("this is the hedder heigth   " + headerHeightOnPage);
        double tableWidthOnPage = tableWidth * scale;
        double oneRowHeight = (table.getRowHeight() +  table.getRowMargin()) * scale;
        int numRowsOnAPage = (int) ( (pageHeight - headerHeightOnPage) / oneRowHeight);
        double pageHeightForTable = oneRowHeight *numRowsOnAPage;
        int totalNumPages = (int) Math.ceil( ( (double) table.getRowCount()) / numRowsOnAPage);
        if (pageIndex >= totalNumPages) {
          return NO_SUCH_PAGE;
        g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    //bottom center
        g2.drawString("Page: " + (pageIndex + 1 + " of " + totalNumPages),  (int) pageWidth / 2 - 35, (int) (pageHeight + fontHeight - fontDesent));
        g2.translate(0f, headerHeightOnPage);
        g2.translate(0f, -pageIndex * pageHeightForTable);
        //If this piece of the table is smaller
        //than the size available,
        //clip to the appropriate bounds.
        if (pageIndex + 1 == totalNumPages) {
          int lastRowPrinted =
              numRowsOnAPage * pageIndex;
          int numRowsLeft =
              table.getRowCount()
              - lastRowPrinted;
          g2.setClip(0,
                     (int) (pageHeightForTable * pageIndex),
                     (int) Math.ceil(tableWidthOnPage),
                     (int) Math.ceil(oneRowHeight *
                                     numRowsLeft));
        //else clip to the entire area available.
        else {
          g2.setClip(0,
                     (int) (pageHeightForTable * pageIndex),
                     (int) Math.ceil(tableWidthOnPage),
                     (int) Math.ceil(pageHeightForTable));
        g2.scale(scale, scale);
        printing = true;
        try {
        table.paint(g2);
        finally {
          printing = false;
        //tableView.paint(g2);
        g2.scale(1 / scale, 1 / scale);
        g2.translate(0f, pageIndex * pageHeightForTable);
        g2.translate(0f, -headerHeightOnPage);
        g2.setClip(0, 0,
                   (int) Math.ceil(tableWidthOnPage),
                   (int) Math.ceil(headerHeightOnPage));
        g2.scale(scale, scale);
        //table.getTableHeader().paint(g2);
        //paint header at top
        return Printable.PAGE_EXISTS;
    class TableRenderDollar extends DefaultTableCellRenderer{
        public Component getTableCellRendererComponent(
          JTable table,
          Object value,
          boolean isSelected,
          boolean isFocused,
          int row, int column) {
            setHorizontalAlignment(SwingConstants.RIGHT);
          Component component = super.getTableCellRendererComponent(
            table,
            value,
            isSelected,
            isFocused,
            row,
            column);
            if( value == null || value .equals("")){
              ( (JLabel) component).setText("");
            }else{
              double number = 0.0;
              number = new Double(value.toString()).doubleValue();
              DecimalFormat df = new DecimalFormat(",##0.00");
              ( (JLabel) component).setText(df.format(number));
          return component;
    }

  • Need some help with a remove function

    Design and code a program that will maintain a list of product names. Use a String type to represent the product name and an array of strings to implement the list. Your program must implement the following methods:
    Add a product to the list
    Remove a product from the list
    Display then entire list
    Find out if a particular product is on the list.
    You need to create a command command loop with a menu() function. The program must continue asking for input until the user stops.
    This is the assignment and this is what I have so far. I need some help writing the remove function.
    Thanks
    * Title: SimpleSearchableList.java
    * Description: this example will show a reasonably efficient and
    * simple algorithm for rearranging the value in an array
    * in ascending order.
    public class SimpleSearchableList {
         private static String[] List = new String[25]; //These variables (field variables)
         private static int Size; //are common to the entire class, but unavailable
         //except to the methods of the class...
         public static void main(String[] args)
              String Cmd;
              for(;;) {
                   Menu();
                   System.out.print("Command: ");
                   Cmd = SimpleIO.inputString();
                   if(Cmd.equals("Quit"))
                        break;
                   else if(Cmd.equals("Fill"))
                        FillList();
                   else if(Cmd.equals("Search"))
                        SearchList();
                   else if(Cmd.equals("Show"))
                        ShowList();
                   else if(Cmd.equals("Remove"))
                        Remove();
         //Tells you what you can do...
         public static void Menu()
              System.out.println("Choices..................................");
              System.out.println("\tFill to Enter Product");
              System.out.println("\tShow to Show Products");
              System.out.println("\tSearch to Search for Product");
              System.out.println("\tRemove a Product");
              System.out.println("\tQuit");
              System.out.println(".........................................");
         //This method will allow the user to fill an array with values...
         public static void FillList()
              int Count;
              System.out.println("Type Stop to Stop");
              for(Count = 0 ; Count < List.length ; Count++)
                   System.out.print("Enter Product: ");
                   List[Count] = SimpleIO.inputString();
                   if(List[Count].equals("Stop"))
                        break;
              Size = Count;
         //This method will rearrange the values in the array so that
         // go from smallest to largest (ascending) order...
         public static void SearchList()
              String KeyValue;
              boolean NotFoundFlag;
              int Z;
              System.out.println("Enter Product Names Below, Stop To Quit");
              while(true)
                   System.out.print("Enter: ");
                   KeyValue = SimpleIO.inputString();
                   if(KeyValue.equals("Stop")) //Note the use of a method for testing
                        break; // for equality...
                   NotFoundFlag = true; //We'll assume the negative
                   for(Z = 0 ; Z < Size ; Z++)
                        if(List[Z].equals(KeyValue)) {
                             NotFoundFlag = false; //If we fine the name, we'll reset the flag
              System.out.println(List[Z] + " was found");
                   if(NotFoundFlag)
                        System.out.println(KeyValue + " was not found");     
         //This method will display the contents of the array...
         public static void ShowList()
              int Z;
              for(Z = 0 ; Z < Size ; Z++)
                   System.out.println("Product " + (Z+1) + " = " + List[Z]);
         public static void Remove()
    }

    I need help removing a product from the arrayYes. So what's your problem?
    "Doctor, I need help."
    "What's wrong?"
    "I need help!"
    Great.
    By the way, you can't remove anything from an array. You'll have to copy the remaining stuff into a new one, or maybe maintain a list of "empty" slots. Or null the slots and handle that. The first way will be the easiest though.

  • Need some help with putting a folder in users directory

    I'm not sure how to do this, but what I want to do is put this file in C:/My Documents, but I need to be able to verify that C://My Documents exists, if not put it in C:/Program Files.
    Can any one help me out?
    try {
                        String[] contactArray = parseDatFile(fc.getSelectedFile());
                        Document document = createXMLDocument(contactArray);
                        saveToXMLFile(
                        document,
                        new File(
                        "C:/Program Files/xxx/",// looks for directory for list
                        "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
                    } catch (Exception exc) {
                        File f = new File("C:/Program Files/xxx/");// setting directory for list if not there
                        boolean yes = true;
                        yes = f.mkdir();// creating directory
                        try {
                            String[] contactArray = parseDatFile(fc.getSelectedFile());
                            Document document = createXMLDocument(contactArray);
                            saveToXMLFile(
                            document,
                            new File(
                            "C:/Program Files/xxx/",// used only if the directory didn't exist
                            "xxxxxxxxxxxxxxxxxxxxxxx"));

    Need some help with putting a folder in users directoryI recomend using System.getProperty( "user.home" ) not a hard-coded value.
    This will use the users home folder ( C:\My Documents ) on Win9X (I guess), C:\Documents and Settings\<current user> on Win2K +, and ~ on Unix-a-likes.

  • Need some help with threads...

    Hello all,
    I am working on a project at work, and I am not the best programmer in the world. I have been trying to get my head around this for a couple of days and just cannot get it to work.
    I am writing an instrumentation control program that will have three threads. One is the GUI, one will receive control information and set up the hardware, and one will check the hardware status and report it to the GUI periodically. I plan on using the invokeLater() method to communicate the status to the GUI and change the status display in the GUI. Communication from the GUI to the controller thread and from the status thread to the controller thread I had planned on being piped input/output stream as appropriate. I have a control class and a status class that need to be communicated over these piped streams. In some trial code I have been unable to wrap the piped input/output streams with object input/output streams. I really need some help with this. Here is the main thread code:
    package playingwiththreads1;
    import java.io.*;*
    *public class PlayingWithThreads1 {*
    public static void main(String[] args) {*
    * PipedOutputStream outputPipe = new PipedOutputStream();*
    * ObjectOutputStream oos = null;*
    * ReceiverThread rt = new ReceiverThread(outputPipe);*
    // Start the thread -- First try*
    * Thread t = new Thread(rt);*
    t.start();*
    // Wrap the output pipe with an ObjectOutputStream*
    try*
    oos = new ObjectOutputStream(outputPipe);*
    catch (IOException e)*
    System.out.println(e);*
    // Start the thread -- Second try*
    //Thread t = new Thread(rt);*
    //t.start();*
    /** Send an object over the pipe. In reality this object will be a
    class that contains control or status information */
    try
    if (!oos.equals(null))
    oos.writeObject(new String ("Test"));
    catch (IOException e)
    try
    Thread.sleep(5000);
    catch (InterruptedException e)
    I read somewhere that it matters where you start the thread relative to where you wrap piped streams with the object streams. So, I tried the two places I felt were obvious to start the thread. These are noted in the comments. Here is the code for the thread.
    package playingwiththreads1;
    import java.io.*;
    public class ReceiverThread implements Runnable {
    private PipedInputStream inputPipe = new PipedInputStream();
    private ObjectInputStream inputObject;
    ReceiverThread (PipedOutputStream outputPipe)
    System.out.println("Thread initialization - start");
    try
    inputPipe.connect(outputPipe);
    inputObject = new ObjectInputStream(inputPipe);
    catch (IOException e)
    System.out.println(e);
    System.out.println("Thread initialization - complete");
    public void run()
    System.out.println("Thread started");
    try
    if (inputObject.available() > 0)
    System.out.println(inputObject.read());
    catch (IOException e)
    System.out.println(e);
    Through testing I have determined that no matter where I start the thread, the thread never gets past the "inputObject = new ObjectInputStream(inputPipe);" assignment.
    Could someone please help me with this? There are other ways for me to write this program, but this is the one that I would like to make work.
    Many thanks in advance,
    Rob Hix
    Edited by: RobertHix on Oct 6, 2009 3:54 AM

    Thanks for the help, but that did not work. I tried flushing the ObjectOutputStream and it is still hanging when initializing the thread.
    Here is a better look at the code since I was helped to figure out how to insert it:
    The main method:
    package playingwiththreads1;
    import java.io.*;
    public class PlayingWithThreads1 {
        public static void main(String[] args) {
            PipedOutputStream outputPipe = new PipedOutputStream();
            ObjectOutputStream oos = null;
            ReceiverThread rt = new ReceiverThread(outputPipe);
            // Start the thread -- First try
            //Thread t = new Thread(rt);
            //t.start();
            // Wrap the output pipe with an ObjectOutputStream
            try
                oos = new ObjectOutputStream(outputPipe);
                oos.flush();
            catch (IOException e)
                System.out.println(e);
            // Start the thread -- Second try
            Thread t = new Thread(rt);
            t.start();
            /* Send an object over the pipe.  In reality this object will be a
             * class that contains control or status information */
            try
                if (!oos.equals(null))
                    oos.writeObject(new String ("Test"));
                    oos.flush();
            catch (IOException e)
                System.out.pringln(e);
            try
                Thread.sleep(5000);
            catch (InterruptedException e)
    }The thread code:
    package playingwiththreads1;
    import java.io.*;
    public class ReceiverThread implements Runnable {
        private PipedInputStream inputPipe = new PipedInputStream();
        private ObjectInputStream inputObject;
        ReceiverThread (PipedOutputStream outputPipe)
            System.out.println("Thread initialization - start");
            try
                inputPipe.connect(outputPipe);
                inputObject = new ObjectInputStream(inputPipe);
            catch (IOException e)
                System.out.println(e);
            System.out.println("Thread initialization - complete");
        public void run()
            System.out.println("Thread started");
            try
                if (inputObject.available() > 0)
                    System.out.println(inputObject.read());
            catch (IOException e)
                System.out.println(e);
    }Does anyone else have and ideas?

  • Need some help with sound quality

    Hi guys, new here. I'm working on creating an album on my own. Bass and vocals are real, everything else is using software instruments. I have about 8 songs done, but the problem is I don't really know what I'm doing as far as recording and levels go.
    I'm using studio headphones and everything sounds fantastic through them, and even pretty good if I just hook up some earbuds, but when I bounce out a track and burn them to do a disc and play it in my car, it sounds awful. Suddenly the guitar is too low, drums are too loud.
    I really need some help here. I'm even willing to pay someone to get me on the right track. Using paypal or whatever.

    AecDuck wrote:
    Where's the fun in that? Maybe you have different motives, but I got into home recording because I like doing things myself, even if I have to learn the hard way. If you know enough to get good bass and vocal recordings and mix that with virtual instruments, then you are well on your way to making a decent sounding mix. Mixing in headphones can be very deceiving. Things simply sound different in headphones. You need some monitors, even if they are crappy because if you can get it to sound good in crappy monitors it will likely sound good on other speakers.
    The fun and experience comes from getting a good balance that sounds good in headphones, and in the monitors, and in your home stereo, and in your car stereo. Use the different audio systems as a reference. If the drums are too quiet in the car, bring them up a bit. If the bass is too loud in your headphones, put them down a bit.
    If you bring in your recordings to be mixed by somebody else, first of all you're going to end up paying hundreds, if not $1000+ dollars, even in a sub-par studio. Secondly, it's never going to sound how you want it to sound. It's going to sound how THEY want it to sound.
    I know it takes longer, and it's hard work, but you will have such a tremendous amount of satisfaction when your project is done knowing that YOU recording it, and YOU mixed it on YOUR equipment. It will be 100% yours.
    Where's the fun? How about the fun in interacting with another human being? How about the satisfaction in having another validate what you've been trying to produce?
    I don't think it's helpful to make generalizations about what type of experience the OP might have in getting professional help. I have had good experiences working with mixing engineers, and perhaps I have just been lucky, but I've been able to produce music that sounded how I wanted it to sound, but at a level beyond which my skill at the time would have been able to produce, AND I gained some insights to help me in the future.
    It IS satisfying to teach yourself a new skill. And it takes a lot of patience, trial and error, and you might miss the mark more often than you hit it. If you're in a rush, it might be a viable solution to contact some studios and see if you can work with them. Learning from others is perfectly acceptable.

  • Need some help with wine + midi

    Howdi guys!
    I need some help. I'd like to run an application which is only available for Windows and OSX, so my choice is wine. This application needs to send midi signals to the hardware it is supposed to control.
    In the product's forum there is a thread which shows how it can be done. But the newest releases of wine don't allow this, because it doesn't support jack anymore.
    I think basically it doesn't matter which application it is I run in wine, the question is, is it possible to send midi signals in and out through wine? If so, how? Might be that it's quite trivial, in my defense I have to say that I never worked with midi before.
    The soundcard I use is an Edirol UA-25 which is fully supported in Linux, midi works.
    Thanks for any ideas!
    edit: Forgot two things: I know I could try older versions of wine or running it in a virtual machine, but I want to avoid this.
    Last edited by Army (2012-04-27 07:15:33)

    For that app, you will probably be using the ALSA-midi interface. So, you shouldn't require Wine to have jack support. - In fact, that picture clearly shows that Wine is using ALSA-midi, but he is using jackd + a2jmidid (which exposes alsa-midi 2 jack-midi).
    As long as that software doesn't require a special driver, you should be able to use it. As for the specifics, i would imagine that you would start jackd, start a2jmidid and then start your application. - you also have to make sure your midi device is connecting before launching your app in wine - otherwise the device won't show up in your wine app. You also will need to select your midi interface in your application. After this, you should be able to connect your wine app (through the a2jmidi bridge) to your hardware.
    But if for whatever reason you can't get it too work ~ i do actually use a VM for updating firmware on 2 different audio devices (a soundcard and midi-controller) - and it works great. I am using VMware, but i would imagine virtualbox would work very similar..
    cheerz

Maybe you are looking for

  • Proxy adapter (XI Adapter)

    Hi masters. I have a doubt about communication with Abap Proxys. Abap proxys attack directly to Integration Engine. My doubt is, this message that arrives to Integration Engine needs to be adapted? There's an adapter in Integration Engine that conver

  • 10.5.2: Expert Advice Needed

    I realize there's a small percentage of the Mac community that believes this, so I'd like it if only experienced mac users of 10+ years would respond. PAST: I've used a mac since 1994, but have been dealing with speed problems of OSX since I first bo

  • 10.6.8 killed my airport

    My iMac worked flawlessly for 3 years.  Today after upgrading to 10.6.8 my iMac WILL NOT stay connected to my wireless network.  It will drop every 2-3 minutes.  The computer has never once done this before....I can only conclude that 10.6.8 is the c

  • Importing existing libraries

    Hi All, I used to have a huge library already imported into lightroom while all the files stored on Drobo (external HD). At some point my main computer died (HD failure). After a full reinstall of the whole system from scratch, including LR I tried t

  • IDVD doesn´t open - Image not founds - immediately  quits

    One week ago, i was building a DVD with iDVD. Everything worked just fine. But today iDVD immediately quits when i´m trying to open it. I am running MAC OSX 10.6.8 and installed the iPhoto and iMovie Update yesterday. The error-message of iDVD says: