NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package component_1;
import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
import java.util.Arrays;
import java.util.Scanner;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
public class DisplayBox extends JFrame{
private JPanel Left;
private JPanel Right;

private JSplitPane splitPanel;
//MenuBar section
JMenuBar menu;
JMenu file;
JMenu help;

JMenuItem load;
JMenuItem save;
JMenuItem exit;
JMenuItem about;

public DisplayBox() {
top();
LeftRight();
}

public void top(){
setLayout(new FlowLayout());
//MENU BAR
menu = new JMenuBar();
setJMenuBar(menu);
//FILE
file = new JMenu("File");
menu.add(file);
//OPEN
load = new JMenuItem("Open");
load.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK));
file.add(load);

loadEvent open = new loadEvent();
load.addActionListener(open);
//SAVE
save = new JMenuItem("Save");
save.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK));
file.add(save);
//EXIT
exit = new JMenuItem("Exit");
exit.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK));
file.add(exit);

exitEvent e = new exitEvent();
exit.addActionListener(e);
//HELP
help = new JMenu("Help");
menu.add(help);
//ABOUT
about = new JMenuItem("About");
about.setAccelerator(KeyStroke.getKeyStroke('A', CTRL_DOWN_MASK));
help.add(about);

aboutEvent ab = new aboutEvent();
about.addActionListener(ab);
}
//ActionListener for EXIT option
public class exitEvent implements ActionListener{
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
//ActionListener for ABOUT option
public class aboutEvent implements ActionListener{
public void actionPerformed(ActionEvent ab) {
JOptionPane.showMessageDialog(null, "ABOUT US."
+ "n" + "PROGRAM LOADS FILES AND FOLDERS AND FROM AND DISPLAYS ON ANOTHER PANEL.","About this Application", JOptionPane.INFORMATION_MESSAGE);

}
}
//ActionListener for OPEN option
public class loadEvent implements ActionListener{
public void actionPerformed(ActionEvent open) {
try {
openFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//Creating Panels
public void LeftRight() {
setLayout(new BorderLayout());
Left= new JPanel();
Left.setBackground(Color.WHITE);
Left.setMinimumSize(new Dimension(50,50));

Right= new JPanel();
Right.setBackground(Color.WHITE);
Right.setMinimumSize(new Dimension(50,50));

splitPanel=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,Left,Right);
splitPanel.setResizeWeight(0.5);
splitPanel.setBounds(100,100,100,100);
splitPanel.setOneTouchExpandable(true);
splitPanel.setContinuousLayout(true);
splitPanel.setAutoscrolls(true);
add(splitPanel,BorderLayout.CENTER);
}

public void openFile() throws IOException
{

JTextArea ta = new JTextArea(40, 30);


JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
chooser.setFileFilter(filter);

int status = chooser.showOpenDialog(null);

if (status != JFileChooser.APPROVE_OPTION) {
JOptionPane.showMessageDialog(null, "No File Chosen");
}
else
{
File file = chooser.getSelectedFile();
Scanner scan = new Scanner(file);




String info = "";

String titleData="";
String YData="";
String XData="";
float XStart=0;
float XInterval=0;
float [] data;

while (scan.hasNext()) {
String temp = scan.nextLine().trim();

if(!temp.isEmpty() && !temp.equals(""))
{

info += temp + "n";
}}
String [] infoToken = info.split("n");

String [] title = infoToken[0].split(":");

if(title[0].equalsIgnoreCase("title")) {
titleData=title[1];
}
else {
JOptionPane.showMessageDialog(null, "Error!!!");
return;
}

String [] Ylabel = infoToken[1].split(":");
if(Ylabel[0].equalsIgnoreCase("ylabel")) {
YData=Ylabel[1];
}
else {
JOptionPane.showMessageDialog(null, "Error!!!");
return;
}

String [] Xlabel = infoToken[2].split(":");
if(Xlabel[0].equalsIgnoreCase("xlabel")) {
XData=Xlabel[1];
}
else {
JOptionPane.showMessageDialog(null, "Error!!!");
return;
}

String [] XStartlabel = infoToken[3].split(":");
if(XStartlabel[0].equalsIgnoreCase("xstart")) {

try {
float tmpfloat= Float.parseFloat(XStartlabel[1]);
XStart = tmpfloat;
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}

}
else {
JOptionPane.showMessageDialog(null, "Error!!!");
return;
}

String [] XIntervalLabel = infoToken[4].split(":");
if(XIntervalLabel[0].equalsIgnoreCase("xinterval")) {

try {
float tmpfloat= Float.parseFloat(XIntervalLabel[1]);
XStart = tmpfloat;
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}

}
else {
JOptionPane.showMessageDialog(null, "Error!!!");
return;
}

String [] dataLabel = infoToken[5].split(",");

float [] datavalue = new float[dataLabel.length];

for (int i=0;i<dataLabel.length;i++) {
try {
Float tmp = Float.parseFloat(dataLabel[i]);
datavalue[i]=tmp;
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
}

ta.setText(info);
ta.setBackground(Color.white);
ta.setForeground(Color.BLACK);
Left.add(ta);
}
}
//class Scrollbar{
//Scrollbar(){
//Frame f= new Frame("Scrollbar");
//Scrollbar s = new Scrollbar();
//..f.setSize(400,400);
//f.setLayout(null);
//f.setVisible(true);
//}

//}

public static void main(String args[]) {
DisplayBox frame = new DisplayBox();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setVisible(true);
frame.setTitle("Frame_GUI");
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.