package maryshelley; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import java.awt.*; import java.awt.event.*; import java.net.URL; import java.io.IOException; /** * * @author Addlient Shaym */ public class MIDlet extends JPanel implements ActionListener { String newline = "\n"; static String[] langtext = getText("/sys/language.lng"); protected static final String buttonString = "JButton"; static String[] toc = loadTableOfContents(false); static String[] tocfile = loadTableOfContents(true); private JList list; String[] filetxt = getText("/txt/text.txt"); public static void main(String[] args) { for (int i = 0; i < toc.length; i++) { System.out.println(toc[i]); } javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } public static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame(langtext[0]); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. MIDlet Shelley = new MIDlet(); frame.setJMenuBar(Shelley.createMenuBar()); //frame.setContentPane(demo.createContentPane()); frame.add(new MIDlet()); //frame.pack(); //Display the window. frame.setSize(450, 260); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // Toolkit tk = Toolkit.getDefaultToolkit(); // int xSize = ((int) tk.getScreenSize().getWidth()); // int ySize = ((int) tk.getScreenSize().getHeight()); // frame.setSize(xSize, ySize); // frame.setUndecorated(true); frame.setVisible(true); } public MIDlet() { setLayout(new BorderLayout()); list = new JList(toc); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); //list.addListSelectionListener(this); JScrollPane listScrollPane = new JScrollPane(list); JTextPane textPane = createTextPane(filetxt); JScrollPane paneScrollPane = new JScrollPane(textPane); paneScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); paneScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); paneScrollPane.setPreferredSize(new Dimension(250, 155)); paneScrollPane.setMinimumSize(new Dimension(10, 10)); //Put the editor pane and the text pane in a split pane. JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listScrollPane, paneScrollPane); splitPane.setOneTouchExpandable(true); splitPane.setResizeWeight(0); JPanel rightPane = new JPanel(new GridLayout(1, 0)); rightPane.add(splitPane); add(rightPane, BorderLayout.CENTER); } protected void updateTextPane(String file){ } private JTextPane createTextPane(String[] filetxt) { java.util.List styles = new ArrayList(); java.util.List doctext = new ArrayList(); String[] possibleStyles = { "[regular]", "[italic]", "[bold]", "[small]", "[large]", "[button]", "[icon]", "[center]" }; for(int i = 0; i lines = new ArrayList(); try ( final InputStream iStream = Runtime.getRuntime().getClass().getResourceAsStream(file); final Reader fIStream = new InputStreamReader(iStream, encoding); final Scanner scanner = new Scanner(fIStream);) { String langline = scanner.nextLine(); // int i = 0; for (int i = 0; langline != null; i++) { if (link) { langline = scanner.nextLine(); } lines.add(langline); langline = scanner.nextLine(); if (!link) { langline = scanner.nextLine(); } } } catch (IOException | NullPointerException | NoSuchElementException | ArrayIndexOutOfBoundsException e) { } String[] text = lines.toArray(new String[lines.size()]); return text; } /** * Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path, String description) { java.net.URL imgURL = MIDlet.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL, description); } else { System.err.println("Couldn't find file: " + path); return null; } } public JMenuBar createMenuBar() { JMenuBar menuBar; JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu(langtext[1]); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem(langtext[2], KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead //menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(langtext[3], KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead //menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); menu.add(menuItem); return menuBar; } public void actionPerformed(ActionEvent e) { if (buttonString.equals(e.getActionCommand())) { Toolkit.getDefaultToolkit().beep(); } JMenuItem source = (JMenuItem) (e.getSource()); if (source.getText().equals(langtext[2])) { String[] aboutText = getText("/sys/about.txt"); JPanel aboutPane = new JPanel(new BorderLayout()); aboutPane.setOpaque(true); JTextPane aboutTextPane = createTextPane(aboutText); JScrollPane aboutScrollPane = new JScrollPane(aboutTextPane); aboutPane.add(aboutScrollPane, BorderLayout.CENTER); JFrame about = new JFrame(langtext[2]); about.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); about.setSize(450, 260); about.setContentPane(aboutPane); about.setVisible(true); } if (source.getText().equals(langtext[3])) { System.exit(0); } } public void valueChanged(ListSelectionEvent e) { JList list = (JList)e.getSource(); //updateLabel(tocfile[list.getSelectedIndex()]); } public static String[] getText(String file) { String encoding = "windows-1251"; java.util.List lines = new ArrayList(); try ( final InputStream iStream = Runtime.getRuntime().getClass().getResourceAsStream(file); final Reader fIStream = new InputStreamReader(iStream, encoding); final Scanner scanner = new Scanner(fIStream);) { String langline = scanner.nextLine(); // int i = 0; for (int i = 0; langline != null; i++) { lines.add(langline); langline = scanner.nextLine(); } } catch (IOException | NullPointerException | NoSuchElementException | ArrayIndexOutOfBoundsException e) { } String[] text = lines.toArray(new String[lines.size()]); return text; } }