p align="left">gridBagConstraints1.gridy = 0; GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.VERTICAL; gridBagConstraints.gridy = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.gridx = 0; jPanel = new JPanel(); jPanel.setLayout(new GridBagLayout()); jPanel.add(getName(), gridBagConstraints); jPanel.add(jLabel, gridBagConstraints1); jPanel.add(jLabel2, gridBagConstraints11); jPanel.add(getLesss(), gridBagConstraints12); } return jPanel; } /** * This method initializes name * * @return javax.swing.JTextField */ private JTextField getName() { if (name == null) { name = new JTextField(); name.setPreferredSize(new Dimension(250, 19)); name.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent e) { if(name.getText().length()>3 & l!=null){ jButton.setEnabled(true); if(e.getKeyChar()=='\n'){ doLogin(); } } else { jButton.setEnabled(false); } } }); } return name; } /** * This method initializes jPanel1 * * @return javax.swing.JPanel */ private JPanel getJPanel1() { if (jPanel1 == null) { jPanel1 = new JPanel(); jPanel1.setLayout(new GridBagLayout()); jPanel1.add(getJButton(), new GridBagConstraints()); } return jPanel1; } /** * This method initializes Lesss * * @return javax.swing.JComboBox */ private JComboBox getLesss() { if (Lesss == null) { Lesss = new JComboBox(); Lesss.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent e) { l=e.getItem().toString(); } }); } return Lesss; } public void Scan(String d){ File dir = new File(d); String[] files = dir.list(); for(int i=0;i<files.length;i++){ if(new File(d+"/"+files[i].toString()+"/"+Main.ftxt).exists()) { addL(files[i].toString()); } } } void addL(String s){ Lesss.addItem(new String(s)); } } Лістинг Main.java: package mahno.masha.smallenglish; import javax.swing.SwingUtilities; public class Main { final static int max_length = 16; static Test test = null; static Login login = null; static String name; static String less; static String workdir; static Words words; final static String ftxt = "words.csv"; final static String lessdir = "lessons/"; final static String iocharset = "UTF-8"; final static String helppage = "system/help.html"; public static void main(String[] args) { workdir = System.getProperty("user.dir")+"/"; doLogin(); } public static void setEnv(String n,String l){ name = n; less = l; login = null; doTest(); } static void doTest(){ test = new Test(); SwingUtilities.invokeLater(new Runnable() { public void run() { test.getJFrame().setVisible(true); } }); words = new Words(workdir,lessdir+less+"/",name,ftxt); } static void doLogin(){ login = new Login(); SwingUtilities.invokeLater(new Runnable() { public void run() { login.getJFrame().setVisible(true); login.Scan(workdir+lessdir); } }); } public static void nextTest(){ words.nextTest(); test.rePaint(); } public static void showHelp() { java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); try { java.net.URI uri = new java.net.URI( "file://"+workdir+helppage ); desktop.browse( uri ); } catch ( Exception er ) { // System.err.println( er.getMessage() ); } } } Лістинг Test.java: package mahno.masha.smallenglish; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.BorderLayout; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import java.awt.Point; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JMenuItem; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JFrame; import javax.swing.JDialog; import javax.swing.Timer; import java.awt.GridBagLayout; import java.awt.Dimension; import javax.swing.JButton; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagConstraints; import java.awt.Color; import java.awt.ComponentOrientation; class Test { final String question = "_"; // @jve:decl-index=0: private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10" private JPanel jContentPane = null; private JMenuBar jJMenuBar = null; private JMenu fileMenu = null; private JMenu helpMenu = null; private JMenuItem exitMenuItem = null; private JMenuItem aboutMenuItem = null; private JDialog aboutDialog = null; private JPanel aboutContentPane = null; private JLabel aboutVersionLabel = null; private JPanel top = null; private JPanel bottom = null; private JPanel left = null; private JPanel right = null; private JPanel screen = null; private JButton button = null; private JPanel pole = null; private int lSize = 50; private JPanel jPanel = null; private Polekeys polekey[] = new Polekeys[Main.max_length]; // @jve:decl-index=0: private Timer timer; final Color bg = new Color(0x5B9DED); final Color bn = new Color(0xE6F0FB); boolean iskey = false; boolean isend = false; boolean cursor = true; private JMenuItem instructionMenuItem = null; public void rePaint() { pole.repaint(); screen.repaint(); } public void setFocus(){ pole.requestFocus(); } /** * This method initializes jFrame * * @return javax.swing.JFrame */ JFrame getJFrame() { if (jFrame == null) { jFrame = new JFrame(); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.setPreferredSize(new Dimension(820, 760)); jFrame.setResizable(false); jFrame.setJMenuBar(getJJMenuBar()); jFrame.setSize(820, 760); jFrame.setContentPane(getJContentPane()); jFrame.setTitle("SmallEnglish"); } return jFrame; } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); jContentPane.setPreferredSize(new Dimension(20, 110)); jContentPane.add(getTop(), BorderLayout.NORTH); jContentPane.add(getBottom(), BorderLayout.SOUTH); jContentPane.add(getLeft(), BorderLayout.WEST); jContentPane.add(getRight(), BorderLayout.EAST); jContentPane.add(getScreen(), BorderLayout.CENTER); jContentPane.setFocusable(false); } return jContentPane; } /** * This method initializes jJMenuBar * * @return javax.swing.JMenuBar */ private JMenuBar getJJMenuBar() { if (jJMenuBar == null) { jJMenuBar = new JMenuBar(); jJMenuBar.add(getFileMenu()); jJMenuBar.add(getHelpMenu()); } return jJMenuBar; } /** * This method initializes jMenu * * @return javax.swing.JMenu */ private JMenu getFileMenu() { if (fileMenu == null) { fileMenu = new JMenu(); fileMenu.setText("Файл"); fileMenu.add(getExitMenuItem()); } return fileMenu; } /** * This method initializes jMenu * * @return javax.swing.JMenu */ private JMenu getHelpMenu() { if (helpMenu == null) { helpMenu = new JMenu(); helpMenu.setText("Допомога"); helpMenu.add(getInstructionMenuItem()); helpMenu.add(getAboutMenuItem()); } return helpMenu; } /** * This method initializes jMenuItem * * @return javax.swing.JMenuItem */ private JMenuItem getExitMenuItem() { if (exitMenuItem == null) { exitMenuItem = new JMenuItem(); exitMenuItem.setText("Вихід"); exitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); } return exitMenuItem; } /** * This method initializes jMenuItem * * @return javax.swing.JMenuItem */ private JMenuItem getAboutMenuItem() { if (aboutMenuItem == null) { aboutMenuItem = new JMenuItem(); aboutMenuItem.setText("Про програму"); aboutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog aboutDialog = getAboutDialog(); aboutDialog.pack(); Point loc = getJFrame().getLocation(); loc.translate(20, 20); aboutDialog.setLocation(loc); aboutDialog.setVisible(true); } }); } return aboutMenuItem; } /** * This method initializes aboutDialog * * @return javax.swing.JDialog */ private JDialog getAboutDialog() { if (aboutDialog == null) {
Страницы: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|