java - How to read from textfile and display specific words(numbers) from that txtfile based on diffrent groups -


How to read from a text file and display specific words (numbers) from that text file based on different groups?

I have a txt file that contains:

  [computer] keyboard = 3 mouse = 5 [animals] cow = 10 pig = 5  < / Pre> 

The numbers will always change with the second program.

I want to create a form that can display like this:

  Cars: 3 keyboards / N 5 mouse animals 10 cow 5 pigs  

I do not know how to do this, I know how to be read from the file but next ...

It is that my frame will see the package for the monocon;

  Import java.awt.BorderLayout; Import java.awt.EventQueue; Import javax.swing.JFrame; Import javax.swing.JPanel; Import javax.swing.border.EmptyBorder; Import javax.swing.JButton; Import javax.swing.JTextArea; Import javax.swing.JTextField; Public class frametast extends to JFrame {Personal JPanel contentPane; / ** * Launch Application * / Public Static Zero Main (String [] Elgus) {EventQueue.invokeLater (New Runnabal) (Runed by Public Zero) ({FrameTest frame = new FrameTest (); frame.setVisible (true) ;} Catch (exception e) {E.printStackTrace ();}}}); } / ** * Create Frame * / Public FrameTest () {setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Setbound (100, 100, 450, 300); ContentPane = new zpn (); ContentPane.setBorder (new blank border (5, 5, 5, 5)); SetContentPane (contentPane); ContentPane.setLayout (zero); Pocket button btncount = new pocket ("count"); BtnCount.setBounds (80, 202, 89, 23); ContentPane.add (btnCount); Jebton BTNRsetset = new pocket ("reset"); BTNRsetsetset bounce (268, 202, 89, 23); ContentPane.add (btnResetCount); JTextArea txtrComputers = new JTextArea (); TxtrComputers.setText ("Computer:"); Txtr ComputerSetbands (24, 59, 84, 22); ContentPane.add (txtrComputers); JTextArea txtrKeyboards = new JTextArea (); TxtrKeyboards.setText ("3 keyboards"); Txtr keyboard Setbound (147, 43, 130, 23); ContentPane.add (txtrKeyboards); JTextArea txtrMouses = new JTextArea (); TxtrMouses.setText ("10 Moles"); TCTMUसेसSetBound (147, 77, 130, 22); ContentPane.add (txtrMouses); JTextArea txtrAnimals = new JTextArea (); TxtrAnimals.setText ("Animals:"); TxtrAnimals.setBounds (24, 133, 84, 22); ContentPane.add (txtrAnimals); JTextArea txtrDogs = new JTextArea (); TxtrDogs.setText ("3 Dogs"); TxtrDogs.setBounds (147, 110, 130, 23); ContentPane.add (txtrDogs); JTextArea txtrCats = new JTextArea (); TxtrCats.setText ("15 Cats"); TxtrCats.setBounds (147, 152, 130, 23); ContentPane.add (txtrCats); }  

}

And when I press the count button, each category will be counted.

This is my .txt file: / P>

  [phone] bad = 1 good = 30 [animals] bad = 10 good = 30  

A possible way to do this is a BufferedReader :

  public class ReadTextFile {public static void main (string [] args ) {Buffer Redirector = Faucet; Try {string currentLine; Br = new BufferedReader (new FileReader ("file.txt")); While ((currentLine = br.readline ()) = Faucet {System.out.println (currentLine); // Test // for your strings from here ("[computer]", etc.)}} hold (IOException ex) {ex.printStackTrace (); } Finally {try {if (br! = Null) {br.close (); }} Hold (IOException pre) {ex.printStackTrace (); }}}}  

I do not know what you really want to do, but I think you will be happy about it.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -