Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,148 members, 7,818,449 topics. Date: Sunday, 05 May 2024 at 04:04 PM

Java Guru Needed, Please Help Me Out. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Guru Needed, Please Help Me Out. (1018 Views)

Muili Seun Sells Off Gocampus To Vickram Sybri, Indian Tech Guru / Html Guru Needed / Java Or .NET Guru Needed In Abuja (2) (3) (4)

(1) (Reply) (Go Down)

Java Guru Needed, Please Help Me Out. by chivirunum(f): 10:31am On Feb 17, 2018
Assuming you have information stored in a text file (information.txt), each COLUMN is separated by a dot and the first ROW contains the row name for each column as follows:

ID.NAME.STATE.SEX.RELIGION.TRIBE
1.Tunde.Lagos.Male.Christian.Yoruba
2.ibrahim.Adamawa.Male.Muslim.Fulani
3.Chinyere.Imo.Female.Christian.Igbo
4.Dooshima.Benue.Female.Atheist.Tiv
5.Halima.Kano.Female.Agnostic.Hausa

• Copy the above data and save it in a text file as “information.txt”
• Using java write a program that takes information from information.txt and displays it on a JTABLE.
• Also create a JBUTTON (Refresh) that adds or removes rows from the table to reflect the current data in information.txt.
Re: Java Guru Needed, Please Help Me Out. by Nobody: 4:18pm On Feb 17, 2018
Show a bit of what you have done.
Re: Java Guru Needed, Please Help Me Out. by chivirunum(f): 6:33pm On Feb 17, 2018
gimakon:
Show a bit of what you have done.
import java.awt.Color;
import java.awt.FlowLayout;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;

import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

public class Information {

public static void main(String[] args){
try {
UIManager.setLookAndFeel(new WindowsLookAndFeel());

} catch (Exception e) {

}

JFrame frame = null;
frame = new JFrame("TABLE"wink;
frame.setLayout(new FlowLayout());
frame.setForeground(Color.decode("#843C0C"wink);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(900, 650);
frame.setResizable(false);
frame.setLocationRelativeTo(null);

JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(0,0,900,650);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
Data info = new Data();
frame.setContentPane(info);
frame.setVisible(true);
frame.setResizable(false);
}

}
class Data extends javax.swing.JPanel {


public Data() {
setBackground(new java.awt.Color(255, 255, 255));
initComponents();
}




private void initComponents() {

refreshButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();

refreshButton.setBackground(new java.awt.Color(132, 60, 12));
refreshButton.setForeground(new java.awt.Color(249, 234, 112));
refreshButton.setText("Refresh"wink;
refreshButton.setContentAreaFilled(false);
refreshButton.setOpaque(true);
refreshButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Methods method = new Methods();
jTable1.setModel(new javax.swing.table.DefaultTableModel(
method.getObject(),
new String [] {
"ID", "NAME", "STATE", "SEX", "RELIGION", "TRIBE"
}
));
}
});

Methods method = new Methods();
jTable1.setModel(new javax.swing.table.DefaultTableModel(
method.getObject(),
new String [] {
"ID", "NAME", "STATE", "SEX", "RELIGION", "TRIBE"
}
));
jScrollPane1.setViewportView(jTable1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(refreshButton)
.addGap(47, 47, 47))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 747, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(refreshButton)
.addContainerGap())
);
}



private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton refreshButton;
}
class Methods {
ArrayList<String> list(String line){
ArrayList<String> array = new ArrayList<String>();
String word = "";
for(int i=0; i<line.length(); i++){
if(line.charAt(i)=='.'){
array.add(word);
word = "";
continue;
}
word+=line.charAt(i);
}
array.add(word);
word = "";
return array;
}

int getRows(){
int rows = 0;
try{
File file = new File("information.txt"wink;
FileReader reader = new FileReader(file);
BufferedReader buffer = new BufferedReader(reader);
String line = "";
while((line = buffer.readLine())!=null){
rows+=1;
}
buffer.close();
}catch(IOException e){
e.printStackTrace();
}
return rows-1;
}
Object[][] getObject(){
Object [][] object = new Object[getRows()][6];
int x = 0;

try{
File file = new File("information.txt"wink;
FileReader reader = new FileReader(file);
BufferedReader buffer = new BufferedReader(reader);
String line = "";
while((line = buffer.readLine())!=null){
if(x>=1){
ArrayList<String> list = list(line);
object[x-1][0] = list.get(0);
object[x-1][1] = list.get(1);
object[x-1][2] = list.get(2);
object[x-1][3] = list.get(3);
object[x-1][4] = list.get(4);
object[x-1][5] = list.get(5);
}
x++;
}
buffer.close();
}catch(IOException e){
e.printStackTrace();
}


return object;
}
}
Re: Java Guru Needed, Please Help Me Out. by Gamelord007: 11:20pm On Feb 17, 2018
try www.post4solution.com a top quality freelance job site that supports Naira transactions

(1) (Reply)

Bill Gates Wrote It In 1999, The Time Is Now / My School Management Software / World's Fastest VPN & Proxy!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.