Random Line Colors? noob needs helppppp :(((

How do you make a program with random line colors heres my program:
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.util.Random;
public class Lab6 extends Applet
     public void paint(Graphics g)      
          g.drawLine(0,300,800,300);
          g.drawLine(400,0,400,600);
          Random rand = new Random(12345);
          for(int x=0;x<=100;x=x+1)
          g.drawLine(rand.nextInt(400),rand.nextInt(300),rand.nextInt(400),rand.nextInt(300));
rand.setSeed(12345);
          for(int x=0;x<=100;x=x+1)
          g.drawLine((rand.nextInt(400) + 400),rand.nextInt(300),(rand.nextInt(400) + 400),rand.nextInt(300));
i need to make random line colors for the second loop and i dont get how. i can only set the lines for the second loop to one color. please help! i'm a real noob. =(

This gets the color with a hex integer. You can use
new Color(seed.nextInt(256), ...
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class Lab6 extends Applet
    Random rand = new Random(12345);
    Random seed = new Random();
    public void paint(Graphics g)
        super.paint(g);
        g.drawLine(0,300,800,300);
        g.drawLine(400,0,400,600);
        for(int x=0;x<=100;x=x+1)
            g.drawLine(rand.nextInt(400),rand.nextInt(300),
                       rand.nextInt(400),rand.nextInt(300));
        rand.setSeed(12345);
        for(int x=0;x<=100;x=x+1)
            g.setColor(getColor());
            g.drawLine((rand.nextInt(400) + 400),rand.nextInt(300),
                       (rand.nextInt(400) + 400),rand.nextInt(300));
    private Color getColor()
        return new Color(seed.nextInt(0xffffff));
    static WindowListener closer = new WindowAdapter()
        public void windowClosing(WindowEvent e)
            System.exit(0);
    public static void main(String[] args)
        Applet applet = new Lab6();
        Frame f = new Frame();
        f.addWindowListener(closer);
        f.add(applet);
        f.setSize(800,600);
        f.setLocation(50,50);
        applet.init();
        f.setVisible(true);
}

Similar Messages

  • Reading a Random Line from a Text File

    Hello,
    I have a program that reads from a text file words. I currently have a text file around 800KB of words. The problem is, if I try to load this into an arraylist so I can use it in my application, it takes wayy long to load. I was wondering if there was a way to just read a random line from the text file.
    Here is my code, and the text file that the program reads from is called 'wordFile'
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class WordColor extends JFrame{
         public WordColor(){
              super("WordColor");
              setSize(1000,500);
              setVisible(true);
              add(new WordPanel());
         public static void main(String[]r){
              JFrame f = new WordColor();
    class WordPanel extends JPanel implements KeyListener{
         private Graphics2D pane;
         private Image img;
         private char[]characterList;
         private CharacterPosition[]positions;
         private int charcounter = 0;
         private String initialWord;
         private File wordFile = new File("C:\\Documents and Settings\\My Documents\\Java\\projects\\WordColorWords.txt");
         private FontMetrics fm;
         private javax.swing.Timer timer;
         public final static int START = 20;
         public final static int delay = 10;
         public final static int BOTTOMLINE = 375;
         public final static int buffer = 15;
         public final static int distance = 4;
         public final static Color[] colors = new Color[]{Color.red,Color.blue,Color.green,Color.yellow,Color.cyan,
                                                                          Color.magenta,Color.orange,Color.pink};
         public static String[] words;
         public static int descent;
         public static int YAXIS = 75;
         public static int SIZE = 72;
         public WordPanel(){
              words = readWords();
              setLayout(new BorderLayout());
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              setFocusable(true);
              addKeyListener(this);
              timer = new javax.swing.Timer(delay,new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        YAXIS += 1;
                        drawWords();
                        if (YAXIS + descent - buffer >= BOTTOMLINE) lose();
                        if (allColorsOn()) win();
         public void paintComponent(Graphics g){
              super.paintComponent(g);
              if (img == null){
                   img = createImage(getWidth(),getHeight());
                   pane = (Graphics2D)img.getGraphics();
                   pane.setColor(Color.white);
                   pane.fillRect(0,0,getWidth(),getHeight());
                   pane.setFont(new Font("Arial",Font.BOLD,SIZE));
                   pane.setColor(Color.black);
                   drawThickLine(pane,getWidth(),5);
                   fm = g.getFontMetrics(new Font("Arial",Font.BOLD,SIZE));
                   descent = fm.getDescent();
                   distributePositions();
                   drawWords();
                   timer.start();
              g.drawImage(img,0,0,this);
         private void distributePositions(){
              int xaxis = START;
              positions = new CharacterPosition[characterList.length];
              int counter = 0;
              for (char c: characterList){
                   CharacterPosition cp = new CharacterPosition(c,xaxis, Color.black);
                   positions[counter] = cp;
                   counter++;
                   xaxis += fm.charWidth(c)+distance;
         private void drawThickLine(Graphics2D pane, int width, int thickness){
              pane.setColor(Color.black);
              for (int j = BOTTOMLINE;j<BOTTOMLINE+1+thickness;j++){
                   pane.drawLine(0,j,width,j);
         private void drawWords(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              drawThickLine(pane,getWidth(),5);
              for (CharacterPosition cp: positions){
                   int x = cp.getX();
                   char print = cp.getChar();
                   pane.setColor(cp.getColor());
                   pane.drawString(""+print,x,YAXIS);
              repaint();
         private boolean allColorsOn(){
              for (CharacterPosition cp: positions){
                   if (cp.getColor() == Color.black) return false;
              return true;
         private Color randomColor(){
              int rand = (int)(Math.random()*colors.length);
              return colors[rand];
         private void restart(){
              charcounter = 0;
              for (CharacterPosition cp: positions){
                   cp.setColor(Color.black);
         private void win(){
              timer.stop();
              newWord();
         private void newWord(){
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              repaint();
              drawThickLine(pane,getWidth(),5);
              YAXIS = 75;
              initialWord = getWord();
              characterList = new char[initialWord.length()];
              for (int i=0; i<initialWord.length();i++){
                   characterList[i] = initialWord.charAt(i);
              distributePositions();
              charcounter = 0;
              drawWords();
              timer.start();
         private void lose(){
              timer.stop();
              pane.setColor(Color.white);
              pane.fillRect(0,0,getWidth(),getHeight());
              pane.setColor(Color.red);
              pane.drawString("Sorry, You Lose!",50,150);
              repaint();
              removeKeyListener(this);
              final JPanel p1 = new JPanel();
              JButton again = new JButton("Play Again?");
              p1.add(again);
              add(p1,"South");
              p1.setBackground(Color.white);
              validate();
              again.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        remove(p1);
                        addKeyListener(WordPanel.this);
                        newWord();
         private String getWord(){
              int rand = (int)(Math.random()*words.length);
              return words[rand];
         private String[] readWords(){
              ArrayList<String> arr = new ArrayList<String>();
              try{
                   BufferedReader buff = new BufferedReader(new FileReader(wordFile));
                   try{
                        String line = null;
                        while (( line = buff.readLine()) != null){
                             line = line.toUpperCase();
                             arr.add(line);
                   finally{
                        buff.close();
              catch(Exception e){e.printStackTrace();}
              Object[] objects = arr.toArray();
              String[] words = new String[objects.length];
              int count = 0;
              for (Object o: objects){
                   words[count] = (String)o;
                   count++;
              return words;
         public void keyPressed(KeyEvent evt){
              char tempchar = evt.getKeyChar();
              String character = ""+tempchar;
              if (character.equalsIgnoreCase(""+positions[charcounter].getChar())){
                   positions[charcounter].setColor(randomColor());
                   charcounter++;
              else if (evt.isShiftDown()){
                   evt.consume();
              else{
                   restart();
              drawWords();
         public void keyTyped(KeyEvent evt){}
         public void keyReleased(KeyEvent evt){}
    class CharacterPosition{
         private int xaxis;
         private char character;
         private Color color;
         public CharacterPosition(char c, int x, Color col){
              xaxis = x;
              character = c;
              color = col;
         public int getX(){
              return xaxis;
         public char getChar(){
              return character;
         public Color getColor(){
              return color;
         public void setColor(Color c){
              color = c;
    }

    I thought that maybe serializing the ArrayList might be faster than creating the ArrayList by iterating over each line in the text file. But alas, I was wrong. Here's my code anyway:
    class WordList extends ArrayList<String>{
      long updated;
    WordList readWordList(File file) throws Exception{
      WordList list = new WordList();
      BufferedReader in = new BufferedReader(new FileReader(file));
      String line = null;
      while ((line = in.readLine()) != null){
        list.add(line);
      in.close();
      list.updated = file.lastModified();
      return list;
    WordList wordList;
    File datFile = new File("words.dat");
    File txtFile = new File("input.txt");
    if (datFile.exists()){
      ObjectInputStream input = new ObjectInputStream(new FileInputStream(datFile));
      wordList = (WordList)input.readObject();
      if (wordList.updated < txtFile.lastModified()){
        //if the text file has been updated, re-read it
        wordList = readWordList(txtFile);
        ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
        output.writeObject(wordList);
        output.close();
    } else {
      //serialized list does not exist--create it
      wordList = readWordList(txtFile);
      ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(datFile));
      output.writeObject(wordList);
      output.close();
    }The text file contained one random sequence of letters per line. For example:
    hwnuu
    nhpgaucah
    zfbylzt
    hwnc
    gicgwkhStats:
    Text file size: 892K
    Serialized file size: 1.1MB
    Time to read from text file: 795ms
    Time to read from serialized file: 1216ms

  • My iPod Touch has had random lines appearing on the screen at certain times (videos, typing)

    My iPod 5 (32gig) has recently started to do this thing where it will show random lines on the screen when either typing quickly or watching certain videos. They are close to the thickness of your fingernails and occasionally vary in color. I've had this iPod for around a year and a half now and it hasn't suffered any significant trauma. When it happens on the keyboard, the lines only appear on the keyboard. When it happens during a video it only happens where the video is playing (ie. if not on full screen, it only happens on the rectangle where the video is, not the empty space). And it also only happens on certain videos. It happened earlier on a news segment clip on the Fox website, but not on a music video I watched on YouTube three minutes later. For videos, it can be up to three of these lines at once. It first started happening to my keyboard and has since furthered itself to the videos. The screen has two small scratches but other than that it's fine. I'd also like to add even though it may not be relevant that my apps have been crashing more recently as well.
    What do you recommend I do? Why is this happening? Thank you in advance!

    Try:
    - Reset the iOS device. Nothing will be lost      
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings                            
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                                              

  • Changing line color on XY plot

    This should be something really simple. I simple created a property node, set the active plot, and set the plot.color. What happens to some plots is the points change to my specified color and other stays as my background plot color which is white. I cant seem to get the line color to change with the point color. There are ways I can change it at run time, by right click on the plot and going into properties and setting line color in that tab.
    What am I doing that I cant get this to work at runtime?
    I attached the plot, just ignore all the missing VIs you should be able to see the problem.
    Attachments:
    SteadyStatePlot1.vi ‏350 KB

    It works just fine here using LabVIEW 7.1. Could you do us a favor and make a mini demo, just containing the xy graph, some data for it, and the related property nodes to demonstrate your problem.
    Overall comment on your VI:
    Sorry, but I am absolutely horrified by your code. I cannot believe that you need all those property nodes, especially the signaling ones, they should be used very sparingly. (For example the FOR loops on top center and in the event called "clear all points" are just pumping hot air, repeating the same action and signaling (!!) every iteration.) It also just cannot be healthy if a single event calls tons of signaling properties, such as in the above mentioned event case. Then, in the timeout event, you are rewriting the plot la
    bels and names every 10 ms. Do they really change that often???
    Please let us help you in your overall program design. It will make a big difference in your future, more complex projects if certain common desing misconceptions are not propagated. I think entire sections of your program can be deleted without loss in functionality, the code can be stripped to <20% and the CPU usage can be reduce to <2% of the current situation. Just my wild guess.
    The above is well meaning criticism, so don't take it personal. I am much harsher looking at my own early code from 8 years ago. :-) Good luck!
    LabVIEW Champion . Do more with less code and in less time .

  • How to read random lines?

    Hi everyone,
    I am trying to write a program that will take a random lines from a number text files and copy them to a new document.
    Is there a way to read specific lines in a document?
    For example if I set an int array to hold 20 random numbers, (23, 504, 498, etc...)
    can i then jump to each of these lines in the document and output the data on each line??
    I have tried the RandomAccessFile seek method but that only moves a certain number of bytes(not lines).
    I have also tried:
    String tempLine = null;
    // where numLines is the total number of lines in the document
    // where randInput is my RandomAccessFile
    For (int i = 0; i < numLines; i++)
    tempLine = (randInput.readLine())
    for(int k = 0; k < 20; k++)
    if(i == randNums[k])
    out.println(tempLine);
    but this method is too slow, as some of my input files are over 500,000 lines in length.
    Can anyone please suggest a faster more efficient method??
    Many Thanks

    If that is really the requirement then I suggest you
    pre-process the file into some other form so it is
    easier to fulfil the requirement.
    For example you could copy the lines into a database
    table, then choose random records from the table. Or
    you could copy the lines into a new file where all
    the lines had the same length (pad with blanks or
    nulls or whatever you need to get back the original
    line), which would make it possible to seek to line N.How about cache first the file, by reading the each line in the file and store that line in an array?
    ie.
    package com.yahoo.ronilloang.idunoifthisright;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    import java.util.Vector;
    * How about caching first then randomly read? This maybe slow or definitely slow in performance.
    * @author     Ronillo Ang
    public class CacheFirstThenRandomlyPick{
         private String[] lines;
         private int lineCount;
         public CacheFirstThenRandomlyPick(String fileName) throws IOException{
              File file = new File(fileName);
              if(file.exists()){
                   BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
                   String line = bufferedReader.readLine();
                   while(line != null){
                        addLine(line);
                        line = bufferedReader.readLine();
                   trim();
                   randomlyPickAndWrite();
                   bufferedReader.close();
         private void addLine(String line){
              if(lines == null)
                   lines = new String[10];
              checkAndExpandCapacityAsNeeded(lineCount + 1);
              lines[lineCount++] = line;
         private void checkAndExpandCapacityAsNeeded(int minCapacity){
              int oldCapacity = lines.length;
              if(minCapacity > oldCapacity){
                   int newCapacity = oldCapacity * 2;
                   while(minCapacity >= newCapacity)
                        newCapacity += 10;
                   String[] oldLines = lines;
                   lines = new String[newCapacity];
                   System.arraycopy(oldLines, 0, lines, 0, lineCount);
         private void trim(){
              if(lineCount > 0 && lineCount < lines.length){
                   String[] oldLines = lines;
                   lines = new String[lineCount];
                   System.arraycopy(oldLines, 0, lines, 0, lineCount);
         private void randomlyPickAndWrite() throws IOException{
              Vector drawnNumber = new Vector();
              BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("out.txt")), "8859_1"));
              for(int index = 0; index < lineCount; ++index){
                   int whatLineToRead = (int)(Math.random() * lineCount);
                   while(drawnNumber.contains(String.valueOf(whatLineToRead)))
                        whatLineToRead = (int)(Math.random() * lineCount);
                   drawnNumber.addElement(String.valueOf(whatLineToRead));
                   bufferedWriter.write(lines[whatLineToRead]);
                   bufferedWriter.newLine();
              bufferedWriter.flush();
              bufferedWriter.close();
         public static void main(String[] args) throws IOException{
              if(args.length == 1){
                   SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss", Locale.getDefault());
                   System.out.println("Program start at " + sdf.format(new Date()));
                   new CacheFirstThenRandomlyPick(args[0]);
                   System.out.println("Program ended at " + sdf.format(new Date()));
              else
                   System.out.println("Usage: java com.yahoo.ronilloang.idunoifthisright.CacheFirstThenRandomlyPick <text file>");
              System.out.println("\ndone.");
    }What do you think? Definitely wrong? Okay. This just what I think. Never mind.
    Thank you. -Ronillo

  • Output corruption, random lines in image

    I needed to make some simple graphics and I ran into something very bad in Illustrator: I cannot save the raster image (PNG or JPG) of the artwork because every time I try to save it I get seemingly random lines in the right half of the image.
    Here is how it looks:
    Five consecutive Save for Webs:
    http://a.imageshack.us/img691/6544/14511159.png
    http://a.imageshack.us/img716/846/87140050.png
    http://a.imageshack.us/img801/9972/82005247.png
    http://a.imageshack.us/img828/6531/84897859.png
    http://a.imageshack.us/img801/6466/56849493.png
    Blown up to 400% in Save for Web dialogue:
    http://a.imageshack.us/img841/6903/85755026.png
    Outer circle alone:
    http://a.imageshack.us/img842/6070/47719222.png
    Here is the .AI file with that circle:
    http://www.mediafire.com/file/48bs6x1rcg5c50r/icon.ai
    My specs:
    Illustrator CS5 + updates
    Windows 7 x64 Ultimate
    Intel Core i7 920
    6GB RAM
    Total pagefile size: 24GB.
    Primary scratch disk - 155GB free.
    Am I missing something or is this a Illustrator bug?

    This is a bug in Illustrator CS5 with Gradient Mesh. As a workaround you may try to flatten your art first from object menu and then save, this will do the trick for you.

  • How can I change line colors in HTML reports?

    I have a VI that is creating an HTML report based on a table of results. I change the back ground color of the line based on failed results. However this line color change is not seen in the HTML reports. Can anyone give me a good way of basically transferring the properties of my table to the HTML report? Is it possible? Thanks in advance for any help.

    Greg - Thanks for the reply. I figured this out doing some more research. The line that I needed was "<BACKLOG="#PAYOFF">Your Cell Text</ID>. The problem I was having was that line is needed in front of the rest of the font formatting commands. For example here is my original line:
    <ID WIDTH="200"><BACKLOG="#PAYOFF"><FONT SIZE=+0 COLOR="#OFF">8.3.12.1</ID>
    The bold part in the line above is what I added. With the cell color added like this it actually created another cell and pushed existing ones one cell to the right. It then colored the second cell in the row and left the first one blank. Through looking up more examples I found that I was actually putting the cell color command in the middle of the font formatting command. So I tried putting it at the end and it then did nothing. The only way I could get the cell in the table to change and not change anything else was using the syntax below.
    <ID BACKLOG="#PAYOFF"><WIDTH="200"><FONT SIZE=+0 COLOR="#OFF">8.3.12.1</ID>
    Troy

  • Line color in JTable

    how can I change line color in JTable.

    Then you need to do custom painting. Something like:
    JTable table = new JTable(...)
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              g.setColor( Color.RED );
              int y = getRowHeight(0) - 1;
              g.drawLine(0, y, getSize().width, y);
    };

  • How to change series or line color in excel 2007 using ActiveX

    I am trying to change series color using Excel 2007 with ActiveX as below. It seems the color cannot be controlled correctly. For example, if I chosse red color, my curve will be changed to blue. Any ideas?
    Also, I googled and found a guy ran into similiar problem using VBA for Excel 2007. See the link below:
    http://help.wugnet.com/office/change-series-line-color-excel-2007-vba-ftopict1062646.html
    Set ch = Worksheets("Chart").ChartObjects(1)
    Set objSeries = ch.Chart.SeriesCollection(1)
    objSeries.Format.Line.ForeColor.RGB = RGB(255, 127, 0)
    According to the post, it need to be done as follows
    objSeries.Border.Color = RGB(255, 127, 0) . But I cannot find the border property/method in ActiveX.
    The color seems to be abitrary. and I found the 

    Xubuli,
    I looked into your question and confirmed that Border.Color is not located under the Excel.Series library. Instead, you must locate it under _Worksheet.UsedRange as seen below in the figure. I am attaching the VI file where I located the the Border.Color property node, and I am also including a SubVI on the block diagram that goes into explicitly set the cell color and border. This SubVI can be found under Programming>>Report Generation>>Excel Specific>>Excel Format>>Excel Set Cell Color and Border.vi, if you have the Report Generation Toolkit installed. I hope this helps.
    Larry H
    Applications Engineer
    National Instruments
    Attachments:
    CellBorder.vi ‏8 KB

  • How to set dash line color(two colors)?

    hello all:
    Does anyone know how to set dash line color in java?
    I only know how to set line color with a single color.
    g2.setColor(Color.black);
    g2.setStroke(dashed);
    g2.draw(new Rectangle2D.Double(50, 50, 200,100));
    what I need to implement is two colors interleave on the dash line.
    so that dash line looks like this:
    ==== ====
    red white red white
    thank you for any comments.
    -Daniel.

    create 2 strokes, space them appropriately, draw the rectangle twice.

  • Can Table Control alternate on line color?

    Is it possible to change line color on Table Control?  I would like the lines on the Table Control to alternate in color as to make it easier to read the data.  I tried using screen-intensifed but that changes the color on a column, I need to make every other row stand out.
    Thanks
    Edited by: Gary Morman on Mar 11, 2010 9:17 PM

    ALV Grid is editable if using the CL_GUI_ALV_GRID class.  See programs which start with BCALV_EDIT*
    Regards,
    Rich Heilman

  • Polar plot line color

    Hello
    I have three vector plotting using polar plot.vi the problem is when I tread to shift the line color, only use black, I need three diferents colors any suggestion?. I put a picture with my block diagram.
    I would like too chance the line width how to I can realice this using mi VI?
    thanks
    Danilo

    Abel_Souza wrote:
    Hi Danilo,
    I think you can use color box contants in a case structure, each case sent one color constat, so you can select colors when you select a case on case structure.
    Regards,
    Well that is part of the story but the picture input tunnel should be changed to a SR if you wnat more than one plot.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • CANT GET RID OF THE ARROW ON MYT LINE TOOL.  CANT CHANGE LINE COLOR.  HELP

    CANT GET RID OF THE ARROW ON MYT LINE TOOL.  CANT CHANGE LINE COLOR.  HELP

    And what are your settings? what system? What version of PS? You need to be more specific and explain better.
    Mylenium

  • TABLE CONTROL LINES COLOR CHANGE

    <i>Hi Friens.,
    I need small help ie.,
    Let us assume we have table control like this.,
    col1 |  col2  |  group |
    a1   |   b1   |  1
    a2   |   b2   |  1
    a3   |   b3   |  2
    a4   |   b4   |  2
    a5   |   b5   |  3
    a6   |   b6   |  3
    1) User need differentiation between groups to look and feel.,thats why I want to change the Line colors based on Group.,
    2) I am getting this one .,but I made case on Sy-stepl.,  while scrolling it is not showing correct .,
    3) Is there any good way to do this., like in ME21   CONDITIONS TAB at Item level</i>
    If any body have Idea., share with me.,
    <b>Thanks.,</b>
    <i><b>Surendher Reddy.Baddam</b></i>

    Re: TABLE CONTROL LINES COLOR CHANGE
    Posted: Nov 5, 2004 6:47 AM        Reply      E-mail this post 
    PBO >>>like thise.,
    LOOP AT itab WITH CONTROL tc4_400 CURSOR tc4_400-current_line.
    MODULE check_rej_hld_400.
    MODULE radio_checkbox_400.
    ENDLOOP.
    >>>
    MODULE radio_checkbox_400.
    DATA : l_stf TYPE i.
    DATA : l_hyd TYPE i,l_knr TYPE i.
    l_hyd = 1.
    LOOP AT SCREEN.
    IF screen-name = 'ITAB-BATCHNO'.
    IF itab-group = l_hyd. " this is group
    screen-intensified = 1.
    MODIFY SCREEN.
    ELSEIF
    screen-intensified = 0.
    MODIFY SCREEN.
    ENDIF.
    ENDIF.
    ENDLOOP.
    ADD 2 TO l_hyd
    ENDMODULE.
    I made logic like this.,
    Thanks.,
    Surendher Reddy.Baddam

  • Random Line reading in text file

    I am trying to read a random line in a text file but every time i read it it reads first line of the file any one can help me what is the problem in the code is or provide me with a new code.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                   File file = new File("word.txt");
                   if(!file.exists())
                        System.out.println("File does not exist.");
                        System.exit(0);
                   try{
                        //Open the file for reading
                        RandomAccessFile raf = new RandomAccessFile(file, "r");
    raf.seek(file.length());     //Seek to end of file
                        System.out.println("Read full line: " + raf.readLine());
    //str2 is a String
                        str2 = str2 + raf.readLine();
                        System.out.println(""+str2);
                        raf.close();
                        System.out.println("Successfully");
                   catch(IOException ioe)
                        System.out.println(ioe.getMessage());
    my text file look like in this format
    mind
    hate
    Abhor
    Bigot
    narrow
    prejudiced
    person
    Counterfeit
    fake
    false
    give
    voting
    rights
    Hamper
    hinder
    obstruct
    Kindle
    to
    start
    fire
    harmful
    poisonous
    lethal

    Next time when posting code, please use code tags: http://forum.java.sun.com/help.jspa?sec=formatting
    A RandomAccessFile has nothing to do with getting a (pseudo) random line number from a file.
    You should also split things up in separate methods:
    - a method for counting the number of lines in a file;
    - a method to get the N-th line from a file.
    In your main method, you call the method which counts the number of lines N in a file and then generate a (pseudo) random number between 1 and N. Use the java.util.Random class for this.
    When you have generated that number, call the other method to get that specific line number.
    Here's a small start:
    import java.io.*;
    import java.util.*;
    public class Main {
        public static String getLineNumber(int number) throws FileNotFoundException {
            // your code here
        public static int countLines(String fileName) throws FileNotFoundException {
            // your code here
        public static void main(String[] args) throws Exception {
            int numberLines = countLines("word.txt");
            Random generator = new Random();
            int randomNumber = generator.nextInt(numberLines)+1;
            String randomLine = getLineNumber(randomNumber);
            System.out.println("Line "+randomNumber+" = '"+randomLine+"'");
    }In both methods, you can use the java.util.Scanner class to read lines from the file.
    Have a look at the API docs of the Scanner class:
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html (including code samples!)
    Good luck.

Maybe you are looking for

  • I recently purchased itunes match, but I get the message "The requested URL was not found on this server".

    I have had problems with playing music on my Iphone 5 from day 1.  I have purchased almost 500 songs in itunes, and only a handful would play.  I decided to purchase IMatch, but playing music is even more difficult.  It quickly skips through my playl

  • Error -36 + Fibre Channel Error Log

    K, so I ran into a very strange occurance. While attempting to copy a 250GB folder of media from one pool to another on an xsan volume, I ended up hitting a single 500 MB file that kept giving me "error -36" in the finder. After the third try, I ende

  • Graphic builder ( to run Drilldown granphs on a web )

    How can i run my existing drilldown graphs on a web. I am having IIS as application server. I don't want to call my graphs from reports as reports. If it is possible to call graphs with the help of graphics server then I want detailed information abo

  • Remove UAC on USB program?

    Aloha, Is there a way to remove the UAC warning on an exe file on a flash drive? If so, how do I do it? WindowsMacMan Parament Technologies

  • How do I import NEF (Nikon RAW file) to iphoto? It fails every time.

    When I put my SD in my card reader, iphoto can preview the files on it. They are NEF format- RAW files from my Nikon DSLR camera. But when I try to import them, the import fails. How do I convert each file to JPG's without doing them separately and c