/** This is the main method for configuring the <it>MyScreenAbout</it>. */ public MyScreenAbout() { // constructor setSize(470, 600); setTitle("informació sobre el MAGNUS"); setResizable(false); Toolkit toolkit = Toolkit.getDefaultToolkit(); URL url = getClass().getResource("icon.png"); Image image = toolkit.getImage(url); setIconImage(image); ScrollPane scrollPane = new ScrollPane(ScrollPane.SCROLLBARS_NEVER); scrollPane.setSize(470, 148); scrollPane.setBackground(new Color(0, 128, 0)); Canvas canvas = new MyCanvasAbout(); canvas.setSize(470, 148); scrollPane.add(canvas); add(scrollPane, BorderLayout.NORTH); ScrollPane infoscroll = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); infoscroll.setSize(470, 400); infoscroll.setBackground(new Color(255, 255, 255)); Panel info = new Panel(); info.setLayout(new GridLayout(56, 1)); infoscroll.add(info); Label ts1 = new Label("MAGNUS 0.1.1"); ts1.setFont(new Font("SansSerif", Font.BOLD, 10)); ts1.setForeground(new Color(0, 0, 0)); ts1.setBackground(new Color(255, 255, 255)); info.add(ts1); Label ts2 = new Label("http://magnusproject.wordpress.com"); ts2.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts2.setForeground(new Color(0, 0, 255)); ts2.setBackground(new Color(255, 255, 255)); info.add(ts2); Label ts3 = new Label(" "); ts3.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts3.setForeground(new Color(0, 0, 255)); ts3.setBackground(new Color(255, 255, 255)); info.add(ts3); Label ts4 = new Label("Alexandre Trilla Castelló"); ts4.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts4.setForeground(new Color(0, 0, 0)); ts4.setBackground(new Color(255, 255, 255)); info.add(ts4); Label ts5 = new Label(" http://www.salle.url.edu/~atrilla/"); ts5.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts5.setForeground(new Color(0, 0, 255)); ts5.setBackground(new Color(255, 255, 255)); info.add(ts5); Label ts7 = new Label("Departament d'Educació de la Generalitat de Catalunya"); ts7.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts7.setForeground(new Color(0, 0, 0)); ts7.setBackground(new Color(255, 255, 255)); info.add(ts7); Label ts8 = new Label(" http://www.xtec.cat"); ts8.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts8.setForeground(new Color(0, 0, 255)); ts8.setBackground(new Color(255, 255, 255)); info.add(ts8); Label ts9 = new Label("Universitat Ramon Llull La Salle Enginyeria de Telecomunicació"); ts9.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts9.setForeground(new Color(0, 0, 0)); ts9.setBackground(new Color(255, 255, 255)); info.add(ts9); Label ts10 = new Label(" http://www.salle.url.edu"); ts10.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts10.setForeground(new Color(0, 0, 255)); ts10.setBackground(new Color(255, 255, 255)); info.add(ts10); Label ts11 = new Label(" "); ts11.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts11.setForeground(new Color(0, 0, 0)); ts11.setBackground(new Color(255, 255, 255)); info.add(ts11); Label ts111 = new Label(" "); ts111.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts111.setForeground(new Color(0, 0, 255)); ts111.setBackground(new Color(255, 255, 255)); info.add(ts111); DesenvCanvas dc = new DesenvCanvas(); info.add(dc); Label ts17 = new Label("MAGNUS ha estat desenvolupat per Alexandre Trilla"); ts17.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts17.setForeground(new Color(0, 0, 0)); ts17.setBackground(new Color(255, 255, 255)); info.add(ts17); Label ts18 = new Label("pel Servei de Tecnologies per l'Aprenentatge i el"); ts18.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts18.setForeground(new Color(0, 0, 0)); ts18.setBackground(new Color(255, 255, 255)); info.add(ts18); Label ts19 = new Label("Coneixement del Departament d'Educació de la"); ts19.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts19.setForeground(new Color(0, 0, 0)); ts19.setBackground(new Color(255, 255, 255)); info.add(ts19); Label ts20 = new Label("Generalitat de Catalunya."); ts20.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts20.setForeground(new Color(0, 0, 0)); ts20.setBackground(new Color(255, 255, 255)); info.add(ts20); Label ts21 = new Label(" "); ts21.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts21.setForeground(new Color(0, 0, 0)); ts21.setBackground(new Color(255, 255, 255)); info.add(ts21); Label ts22 = new Label("Alhora, MAGNUS ha constituït el Projecte Final de"); ts22.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts22.setForeground(new Color(0, 0, 0)); ts22.setBackground(new Color(255, 255, 255)); info.add(ts22); Label ts23 = new Label("Carrera de l'autor, havent cursat d'Enginyeria"); ts23.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts23.setForeground(new Color(0, 0, 0)); ts23.setBackground(new Color(255, 255, 255)); info.add(ts23); Label ts24 = new Label("Superior de Telecomunicacions a la Universitat"); ts24.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts24.setForeground(new Color(0, 0, 0)); ts24.setBackground(new Color(255, 255, 255)); info.add(ts24); Label ts25 = new Label("Ramon Llull La Salle de Barcelona."); ts25.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts25.setForeground(new Color(0, 0, 0)); ts25.setBackground(new Color(255, 255, 255)); info.add(ts25); Label ts26 = new Label(" "); ts26.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts26.setForeground(new Color(0, 0, 0)); ts26.setBackground(new Color(255, 255, 255)); info.add(ts26); Label ts261 = new Label(" "); ts261.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts261.setForeground(new Color(0, 0, 0)); ts261.setBackground(new Color(255, 255, 255)); info.add(ts261); CredenCanvas cc = new CredenCanvas(); info.add(cc); Label ts12 = new Label("Aquest producte inclou programari desenvolupat per:"); ts12.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts12.setForeground(new Color(0, 0, 0)); ts12.setBackground(new Color(255, 255, 255)); info.add(ts12); Label ts121 = new Label(" "); ts121.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts121.setForeground(new Color(0, 0, 0)); ts121.setBackground(new Color(255, 255, 255)); info.add(ts121); Label ts13 = new Label("Sphinx-4"); ts13.setFont(new Font("SansSerif", Font.BOLD, 10)); ts13.setForeground(new Color(0, 0, 0)); ts13.setBackground(new Color(255, 255, 255)); info.add(ts13); Label ts14 = new Label("Carnegie Mellon University"); ts14.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts14.setForeground(new Color(0, 0, 0)); ts14.setBackground(new Color(255, 255, 255)); info.add(ts14); Label ts142 = new Label(" http://cmusphinx.sourceforge.net/sphinx4/"); ts142.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts142.setForeground(new Color(0, 0, 255)); ts142.setBackground(new Color(255, 255, 255)); info.add(ts142); Label ts141 = new Label(" "); ts141.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts141.setForeground(new Color(0, 0, 0)); ts141.setBackground(new Color(255, 255, 255)); info.add(ts141); Label ts15 = new Label("Jdom"); ts15.setFont(new Font("SansSerif", Font.BOLD, 10)); ts15.setForeground(new Color(0, 0, 0)); ts15.setBackground(new Color(255, 255, 255)); info.add(ts15); Label ts16 = new Label("The JDOM Project"); ts16.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts16.setForeground(new Color(0, 0, 0)); ts16.setBackground(new Color(255, 255, 255)); info.add(ts16); Label ts162 = new Label(" http://www.jdom.org"); ts162.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts162.setForeground(new Color(0, 0, 255)); ts162.setBackground(new Color(255, 255, 255)); info.add(ts162); Label ts161 = new Label(" "); ts161.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts161.setForeground(new Color(0, 0, 0)); ts161.setBackground(new Color(255, 255, 255)); info.add(ts161); Label ts163 = new Label(" "); ts163.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts163.setForeground(new Color(0, 0, 0)); ts163.setBackground(new Color(255, 255, 255)); info.add(ts163); LicCanvas lc = new LicCanvas(); info.add(lc); Label ts64 = new Label("Copyright (C) 2007 Alexandre Trilla &"); ts64.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts64.setForeground(new Color(0, 0, 0)); ts64.setBackground(new Color(255, 255, 255)); info.add(ts64); Label ts65 = new Label("Departament d'Educació de la Generalitat de Catalunya &"); ts65.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts65.setForeground(new Color(0, 0, 0)); ts65.setBackground(new Color(255, 255, 255)); info.add(ts65); Label ts66 = new Label("Universitat Ramon Llull La Salle Enginyeria de Telecomunicació"); ts66.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts66.setForeground(new Color(0, 0, 0)); ts66.setBackground(new Color(255, 255, 255)); info.add(ts66); Label ts67 = new Label(" "); ts67.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts67.setForeground(new Color(0, 0, 0)); ts67.setBackground(new Color(255, 255, 255)); info.add(ts67); Label ts68 = new Label("Aquest programa és lliure. Podeu distribuir-lo i/o modificar-"); ts68.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts68.setForeground(new Color(0, 0, 0)); ts68.setBackground(new Color(255, 255, 255)); info.add(ts68); Label ts69 = new Label("lo conforme a les disposicions de la Llicència Pública General"); ts69.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts69.setForeground(new Color(0, 0, 0)); ts69.setBackground(new Color(255, 255, 255)); info.add(ts69); Label ts70 = new Label("de GNU (GPL), publicada per la Free Software Foundation, ja"); ts70.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts70.setForeground(new Color(0, 0, 0)); ts70.setBackground(new Color(255, 255, 255)); info.add(ts70); Label ts71 = new Label("sigui la versió 3 de la llicència o qualsevol versió posterior."); ts71.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts71.setForeground(new Color(0, 0, 0)); ts71.setBackground(new Color(255, 255, 255)); info.add(ts71); Label ts711 = new Label(" "); ts711.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts711.setForeground(new Color(0, 0, 0)); ts711.setBackground(new Color(255, 255, 255)); info.add(ts711); Label ts72 = new Label("Aquest programa es distribueix amb la intenció de resultar"); ts72.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts72.setForeground(new Color(0, 0, 0)); ts72.setBackground(new Color(255, 255, 255)); info.add(ts72); Label ts73 = new Label("útil, però SENSE CAP GARANTIA, fins i tot sense la garantia"); ts73.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts73.setForeground(new Color(0, 0, 0)); ts73.setBackground(new Color(255, 255, 255)); info.add(ts73); Label ts74 = new Label("implícita de COMERCIABILITAT o CONVENIÈNCIA PER A UN"); ts74.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts74.setForeground(new Color(0, 0, 0)); ts74.setBackground(new Color(255, 255, 255)); info.add(ts74); Label ts75 = new Label("PROPÒSIT PARTICULAR. Per a més detalls, vegeu la Llicència"); ts75.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts75.setForeground(new Color(0, 0, 0)); ts75.setBackground(new Color(255, 255, 255)); info.add(ts75); Label ts76 = new Label("Pública General de GNU."); ts76.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts76.setForeground(new Color(0, 0, 0)); ts76.setBackground(new Color(255, 255, 255)); info.add(ts76); Label ts77 = new Label(" "); ts77.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts77.setForeground(new Color(0, 0, 0)); ts77.setBackground(new Color(255, 255, 255)); info.add(ts77); Label ts771 = new Label(" "); ts771.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts771.setForeground(new Color(0, 0, 0)); ts771.setBackground(new Color(255, 255, 255)); info.add(ts771); SupCanvas supc = new SupCanvas(); info.add(supc); Label ts1234 = new Label("Desenvolupat en col·laboració amb Enginyeria i"); ts1234.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts1234.setForeground(new Color(0, 0, 0)); ts1234.setBackground(new Color(255, 255, 255)); info.add(ts1234); Label ts12345 = new Label("Arquitectura La Salle (Universitat Ramon Llull)"); ts12345.setFont(new Font("SansSerif", Font.PLAIN, 10)); ts12345.setForeground(new Color(0, 0, 0)); ts12345.setBackground(new Color(255, 255, 255)); info.add(ts12345); SalleCanvas sallec = new SalleCanvas(); // info.add(sallec); add(sallec, BorderLayout.SOUTH); add(infoscroll, BorderLayout.CENTER); addWindowListener( new WindowAdapter() { /** * This method catches the closing event and react accordingly. * * @param e WindowEvent: the window closing event. */ public void windowClosing(WindowEvent e) { setVisible(false); } }); }
public void setupDBFields(String dbname) throws Exception { viewPane.setLayout(null); Dimension dimView = sp.getSize(); int height = 0, width = 50; viewPane.removeAll(); db = new DBF(dbname); setTitle(dbname); gb = new GridBagLayout(); gbc = new GridBagConstraints(); viewPane.setLayout(gb); int i, j; fldObjects = new Vector(db.getFieldCount()); for (i = 1; i <= db.getFieldCount(); i++) { j = i - 1; f = db.getField(i); if (f.isMemoField() || f.isPictureField()) { b = new Button(db.getField(i).getName()); b.addActionListener(this); addComponent( viewPane, b, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); fldObjects.addElement(b); } else if (f.getType() == 'L') { c = new Checkbox(db.getField(i).getName(), true); addComponent( viewPane, c, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); fldObjects.addElement(c); } else { l = new Label(db.getField(i).getName(), Label.RIGHT); addComponent( viewPane, l, 0, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); int ln = f.getLength(); if (ln > 100) { ln = 100; } t = new TextField(db.getField(i).getName(), ln); if (width < ln * 10) { width = ln * 10; } addComponent( viewPane, t, 1, j, ln, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); fldObjects.addElement(t); t.setEditable(true); } height += 10; } crl.setText("Record " + db.getCurrentRecordNumber()); trl.setText(" of " + db.getRecordCount()); SBrecpos.setMaximum(db.getRecordCount()); addComponent(viewPane, crl, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent(viewPane, trl, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); i++; addComponent( viewPane, SBrecpos, 0, i, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, delCB, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); i++; addComponent( viewPane, Prev, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, Next, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); i++; addComponent(viewPane, Add, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, Update, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, Clear, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); Prev.setEnabled(false); prevRecord.setEnabled(false); if (db.getRecordCount() == 0) { Update.setEnabled(false); updateRecord.setEnabled(false); Next.setEnabled(false); nextRecord.setEnabled(false); } dimView.setSize(width + 150, height + 150); sp.setSize(dimView); goTo(1); }
/** Create the whole GUI, and set up event listeners */ public AllComponents(String title) { super(title); // set frame title. // Arrange to detect window close events this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); // Set a default font this.setFont(new Font("SansSerif", Font.PLAIN, 12)); // Create the menubar. Tell the frame about it. MenuBar menubar = new MenuBar(); this.setMenuBar(menubar); // Create the file menu. Add to menubar. Menu file = new Menu("File"); menubar.add(file); // Create two items for the file menu, setting their label, shortcut, // action command and listener. Add them to File menu. // Note that we use the frame itself as the action listener MenuItem open = new MenuItem("Open", new MenuShortcut(KeyEvent.VK_O)); open.setActionCommand("open"); open.addActionListener(this); file.add(open); MenuItem quit = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q)); quit.setActionCommand("quit"); quit.addActionListener(this); file.add(quit); // Create Help menu; add an item; add to menubar // Display the help menu in a special reserved place. Menu help = new Menu("Help"); menubar.add(help); menubar.setHelpMenu(help); // Create and add an item to the Help menu MenuItem about = new MenuItem("About", new MenuShortcut(KeyEvent.VK_A)); about.setActionCommand("about"); about.addActionListener(this); help.add(about); // Now that we've done the menu, we can begin work on the contents of // the frame. Assign a BorderLayout manager with margins for this frame. this.setLayout(new BorderLayout(10, 10)); // Create two panels to contain two columns of components. Use our custom // ColumnLayout layout manager for each. Add them on the west and // center of the frame's border layout Panel column1 = new Panel(); column1.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT)); this.add(column1, "West"); Panel column2 = new Panel(); column2.setLayout(new ColumnLayout(5, 10, 2, ColumnLayout.LEFT)); this.add(column2, "Center"); // Create a panel to contain the buttons at the bottom of the window // Give it a FlowLayout layout manager, and add it along the south border Panel buttonbox = new Panel(); buttonbox.setLayout(new FlowLayout(FlowLayout.CENTER, 100, 10)); this.add(buttonbox, "South"); // Create pushbuttons and add them to the buttonbox Button okay = new Button("Okay"); Button cancel = new Button("Cancel"); buttonbox.add(okay); buttonbox.add(cancel); // Handle events on the buttons ActionListener buttonlistener = new ActionListener() { public void actionPerformed(ActionEvent e) { textarea.append("You clicked: " + ((Button) e.getSource()).getLabel() + "\n"); } }; okay.addActionListener(buttonlistener); cancel.addActionListener(buttonlistener); // Now start filling the left column. // Create a 1-line text field and add to left column, with a label TextField textfield = new TextField(15); column1.add(new Label("Name:")); column1.add(textfield); // Handle events on the TextField textfield.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { textarea.append("Your name is: " + ((TextField) e.getSource()).getText() + "\n"); } }); textfield.addTextListener( new TextListener() { public void textValueChanged(TextEvent e) { textarea.append("You have typed: " + ((TextField) e.getSource()).getText() + "\n"); } }); // Create a dropdown list or option menu of choices Choice choice = new Choice(); choice.addItem("red"); choice.addItem("green"); choice.addItem("blue"); column1.add(new Label("Favorite color:")); column1.add(choice); // Handle events on this choice choice.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { textarea.append("Your favorite color is: " + e.getItem() + "\n"); } }); // Create checkboxes, and group them in a CheckboxGroup to give them // "radio button" behavior. CheckboxGroup checkbox_group = new CheckboxGroup(); Checkbox[] checkboxes = new Checkbox[3]; checkboxes[0] = new Checkbox("vanilla", checkbox_group, false); checkboxes[1] = new Checkbox("chocolate", checkbox_group, true); checkboxes[2] = new Checkbox("strawberry", checkbox_group, false); column1.add(new Label("Favorite flavor:")); for (int i = 0; i < checkboxes.length; i++) column1.add(checkboxes[i]); // Handle events on the checkboxes ItemListener checkbox_listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { textarea.append( "Your favorite flavor is: " + ((Checkbox) e.getItemSelectable()).getLabel() + "\n"); } }; for (int i = 0; i < checkboxes.length; i++) checkboxes[i].addItemListener(checkbox_listener); // Create a list of choices. List list = new List(4, true); list.addItem("Java"); list.addItem("C"); list.addItem("C++"); list.addItem("Smalltalk"); list.addItem("Lisp"); list.addItem("Modula-3"); list.addItem("Forth"); column1.add(new Label("Favorite languages:")); column1.add(list); // Handle events on this list list.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent e) { textarea.append("Your favorite languages are: "); String[] languages = ((List) e.getItemSelectable()).getSelectedItems(); for (int i = 0; i < languages.length; i++) { if (i > 0) textarea.append(","); textarea.append(languages[i]); } textarea.append("\n"); } }); // Create a multi-line text area in column 2 textarea = new TextArea(6, 40); textarea.setEditable(false); column2.add(new Label("Messages")); column2.add(textarea); // Create a scrollpane that displays portions of a larger component ScrollPane scrollpane = new ScrollPane(); scrollpane.setSize(300, 150); column2.add(new Label("Scrolling Window")); column2.add(scrollpane); // Create a custom MultiLineLabel with a really big font and make it // a child of the ScrollPane container String message = "/*************************************************\n" + " * AllComponents.java *\n" + " * Written by David Flanagan *\n" + " * Copyright (c) 1997 by O'Reilly & Associates *\n" + " * *\n" + " *************************************************/\n"; MultiLineLabel biglabel = new MultiLineLabel(message); biglabel.setFont(new Font("Monospaced", Font.BOLD + Font.ITALIC, 24)); scrollpane.add(biglabel); }