/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package notatnik;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class Main {
static JTextPane jtp;
public static void main(String[] args) {
JFrame formularz = createForm();
formularz.setVisible(true);
}
public static JFrame createForm(){
JFrame tmp = new JFrame("Notatnik");
tmp.setSize(400,400);
Container c = tmp.getContentPane();
c.setLayout(new BorderLayout());
c.setBackground(Color.red);
JTabbedPane jtp = new JTabbedPane();
JPanel jp = createJPanel("pierwszy");
jtp.addTab("1",jp);
JMenuBar menu = createMenu();
c.add(menu, BorderLayout.NORTH);
c.add(jtp, BorderLayout.CENTER);
return tmp;
}
public static JPanel createJPanel(String label){
JPanel jpl = new JPanel();
jpl.setLayout(new BorderLayout());
JLabel lab = new JLabel(label);
jpl.add(lab, BorderLayout.PAGE_START);
jtp = new JTextPane();
jpl.add(jtp, BorderLayout.CENTER);
return jpl;
}
public static JMenuBar createMenu(){
JMenuBar tmp = new JMenuBar();
JMenu plik = new JMenu("Plik");
tmp.add(plik);
JMenuItem otworz = new JMenuItem("Otwórz");
otworz.addActionListener(new MojListener());
plik.add(otworz);
return tmp;
}
}
class MojListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
Document d =Main.jtp.getStyledDocument();
try {
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(Main.jtp);
File selectedFile = jfc.getSelectedFile();
d.insertString(0, selectedFile.getName() , null);
} catch (Exception ex) {
Logger.getLogger(MojListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}