Source Code Cross Referenced for PeriodicTable.java in  » Science » JSci » examples » PeriodicTable » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » JSci » examples.PeriodicTable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        import java.awt.*;
002:        import java.awt.event.*;
003:        import JSci.chemistry.*;
004:        import JSci.chemistry.periodictable.*;
005:
006:        /**
007:         * Periodic Table.
008:         * This will run under the J2ME Personal Profile.
009:         * @author Mark Hale
010:         * @version 1.4
011:         */
012:        public final class PeriodicTable extends Frame {
013:            private static final Color purple = new Color(0.75f, 0.75f, 1.0f);
014:            private static final boolean showNumbering = true;
015:
016:            public static void main(String argv[]) {
017:                new PeriodicTable();
018:            }
019:
020:            private static void setDefaultSize(Component c, int defaultWidth,
021:                    int defaultHeight) {
022:                Dimension screenSize = Toolkit.getDefaultToolkit()
023:                        .getScreenSize();
024:                final int width = (defaultWidth < screenSize.width) ? defaultWidth
025:                        : screenSize.width;
026:                final int height = (defaultHeight < screenSize.height) ? defaultHeight
027:                        : screenSize.height;
028:                c.setSize(width, height);
029:            }
030:
031:            public PeriodicTable() {
032:                super ("Periodic Table");
033:                addWindowListener(new WindowAdapter() {
034:                    public void windowClosing(WindowEvent evt) {
035:                        dispose();
036:                        System.exit(0);
037:                    }
038:                });
039:                System.out.print("Loading elements...");
040:                Panel panel = new Panel();
041:                createTable(panel, this );
042:                System.out.println("done.");
043:                ScrollPane scrollPane = new ScrollPane();
044:                scrollPane.add(panel);
045:                add(scrollPane);
046:                setDefaultSize(this , 650, 400);
047:                setVisible(true);
048:            }
049:
050:            private static void createTable(Container container, Frame frame) {
051:                GridBagLayout gb = new GridBagLayout();
052:                GridBagConstraints gbc = new GridBagConstraints();
053:                gbc.fill = GridBagConstraints.BOTH;
054:                container.setLayout(gb);
055:                gbc.gridy = 0;
056:                if (showNumbering) {
057:                    gbc.gridx = 1;
058:                    container.add(createLabel("1", gb, gbc));
059:                    gbc.gridx++;
060:                    container.add(createLabel("2", gb, gbc));
061:                    gbc.gridx++;
062:                    container.add(createLabel("3", gb, gbc));
063:                    gbc.gridx++;
064:                    container.add(createLabel("4", gb, gbc));
065:                    gbc.gridx++;
066:                    container.add(createLabel("5", gb, gbc));
067:                    gbc.gridx++;
068:                    container.add(createLabel("6", gb, gbc));
069:                    gbc.gridx++;
070:                    container.add(createLabel("7", gb, gbc));
071:                    gbc.gridx++;
072:                    container.add(createLabel("8", gb, gbc));
073:                    gbc.gridx++;
074:                    container.add(createLabel("9", gb, gbc));
075:                    gbc.gridx++;
076:                    container.add(createLabel("10", gb, gbc));
077:                    gbc.gridx++;
078:                    container.add(createLabel("11", gb, gbc));
079:                    gbc.gridx++;
080:                    container.add(createLabel("12", gb, gbc));
081:                    gbc.gridx++;
082:                    container.add(createLabel("13", gb, gbc));
083:                    gbc.gridx++;
084:                    container.add(createLabel("14", gb, gbc));
085:                    gbc.gridx++;
086:                    container.add(createLabel("15", gb, gbc));
087:                    gbc.gridx++;
088:                    container.add(createLabel("16", gb, gbc));
089:                    gbc.gridx++;
090:                    container.add(createLabel("17", gb, gbc));
091:                    gbc.gridx++;
092:                    container.add(createLabel("18", gb, gbc));
093:                    gbc.gridy++;
094:                }
095:                gbc.gridx = 0;
096:                if (showNumbering) {
097:                    container.add(createLabel("1", gb, gbc));
098:                    gbc.gridx++;
099:                }
100:                container.add(createButton("Hydrogen", gb, gbc, frame));
101:                gbc.gridx += 17;
102:                container.add(createButton("Helium", gb, gbc, frame));
103:                gbc.gridx = 0;
104:                gbc.gridy++;
105:                if (showNumbering) {
106:                    container.add(createLabel("2", gb, gbc));
107:                    gbc.gridx++;
108:                }
109:                container.add(createButton("Lithium", gb, gbc, frame));
110:                gbc.gridx++;
111:                container.add(createButton("Beryllium", gb, gbc, frame));
112:                gbc.gridx += 11;
113:                container.add(createButton("Boron", gb, gbc, frame));
114:                gbc.gridx++;
115:                container.add(createButton("Carbon", gb, gbc, frame));
116:                gbc.gridx++;
117:                container.add(createButton("Nitrogen", gb, gbc, frame));
118:                gbc.gridx++;
119:                container.add(createButton("Oxygen", gb, gbc, frame));
120:                gbc.gridx++;
121:                container.add(createButton("Fluorine", gb, gbc, frame));
122:                gbc.gridx++;
123:                container.add(createButton("Neon", gb, gbc, frame));
124:                gbc.gridx = 0;
125:                gbc.gridy++;
126:                if (showNumbering) {
127:                    container.add(createLabel("3", gb, gbc));
128:                    gbc.gridx++;
129:                }
130:                container.add(createButton("Sodium", gb, gbc, frame));
131:                gbc.gridx++;
132:                container.add(createButton("Magnesium", gb, gbc, frame));
133:                gbc.gridx += 11;
134:                container.add(createButton("Aluminium", gb, gbc, frame));
135:                gbc.gridx++;
136:                container.add(createButton("Silicon", gb, gbc, frame));
137:                gbc.gridx++;
138:                container.add(createButton("Phosphorus", gb, gbc, frame));
139:                gbc.gridx++;
140:                container.add(createButton("Sulphur", gb, gbc, frame));
141:                gbc.gridx++;
142:                container.add(createButton("Chlorine", gb, gbc, frame));
143:                gbc.gridx++;
144:                container.add(createButton("Argon", gb, gbc, frame));
145:                gbc.gridx = 0;
146:                gbc.gridy++;
147:                if (showNumbering) {
148:                    container.add(createLabel("4", gb, gbc));
149:                    gbc.gridx++;
150:                }
151:                container.add(createButton("Potassium", gb, gbc, frame));
152:                gbc.gridx++;
153:                container.add(createButton("Calcium", gb, gbc, frame));
154:                gbc.gridx++;
155:                container.add(createButton("Scandium", gb, gbc, frame));
156:                gbc.gridx++;
157:                container.add(createButton("Titanium", gb, gbc, frame));
158:                gbc.gridx++;
159:                container.add(createButton("Vanadium", gb, gbc, frame));
160:                gbc.gridx++;
161:                container.add(createButton("Chromium", gb, gbc, frame));
162:                gbc.gridx++;
163:                container.add(createButton("Manganese", gb, gbc, frame));
164:                gbc.gridx++;
165:                container.add(createButton("Iron", gb, gbc, frame));
166:                gbc.gridx++;
167:                container.add(createButton("Cobalt", gb, gbc, frame));
168:                gbc.gridx++;
169:                container.add(createButton("Nickel", gb, gbc, frame));
170:                gbc.gridx++;
171:                container.add(createButton("Copper", gb, gbc, frame));
172:                gbc.gridx++;
173:                container.add(createButton("Zinc", gb, gbc, frame));
174:                gbc.gridx++;
175:                container.add(createButton("Gallium", gb, gbc, frame));
176:                gbc.gridx++;
177:                container.add(createButton("Germanium", gb, gbc, frame));
178:                gbc.gridx++;
179:                container.add(createButton("Arsenic", gb, gbc, frame));
180:                gbc.gridx++;
181:                container.add(createButton("Selenium", gb, gbc, frame));
182:                gbc.gridx++;
183:                container.add(createButton("Bromine", gb, gbc, frame));
184:                gbc.gridx++;
185:                container.add(createButton("Krypton", gb, gbc, frame));
186:                gbc.gridx = 0;
187:                gbc.gridy++;
188:                if (showNumbering) {
189:                    container.add(createLabel("5", gb, gbc));
190:                    gbc.gridx++;
191:                }
192:                container.add(createButton("Rubidium", gb, gbc, frame));
193:                gbc.gridx++;
194:                container.add(createButton("Strontium", gb, gbc, frame));
195:                gbc.gridx++;
196:                container.add(createButton("Yttrium", gb, gbc, frame));
197:                gbc.gridx++;
198:                container.add(createButton("Zirconium", gb, gbc, frame));
199:                gbc.gridx++;
200:                container.add(createButton("Niobium", gb, gbc, frame));
201:                gbc.gridx++;
202:                container.add(createButton("Molybdenum", gb, gbc, frame));
203:                gbc.gridx++;
204:                container.add(createButton("Technetium", gb, gbc, frame));
205:                gbc.gridx++;
206:                container.add(createButton("Ruthenium", gb, gbc, frame));
207:                gbc.gridx++;
208:                container.add(createButton("Rhodium", gb, gbc, frame));
209:                gbc.gridx++;
210:                container.add(createButton("Palladium", gb, gbc, frame));
211:                gbc.gridx++;
212:                container.add(createButton("Silver", gb, gbc, frame));
213:                gbc.gridx++;
214:                container.add(createButton("Cadmium", gb, gbc, frame));
215:                gbc.gridx++;
216:                container.add(createButton("Indium", gb, gbc, frame));
217:                gbc.gridx++;
218:                container.add(createButton("Tin", gb, gbc, frame));
219:                gbc.gridx++;
220:                container.add(createButton("Antimony", gb, gbc, frame));
221:                gbc.gridx++;
222:                container.add(createButton("Tellurium", gb, gbc, frame));
223:                gbc.gridx++;
224:                container.add(createButton("Iodine", gb, gbc, frame));
225:                gbc.gridx++;
226:                container.add(createButton("Xenon", gb, gbc, frame));
227:                gbc.gridx = 0;
228:                gbc.gridy++;
229:                if (showNumbering) {
230:                    container.add(createLabel("6", gb, gbc));
231:                    gbc.gridx++;
232:                }
233:                container.add(createButton("Caesium", gb, gbc, frame));
234:                gbc.gridx++;
235:                container.add(createButton("Barium", gb, gbc, frame));
236:                gbc.gridx++;
237:                container.add(createButton("Lanthanum", gb, gbc, frame));
238:                gbc.gridx++;
239:                container.add(createButton("Hafnium", gb, gbc, frame));
240:                gbc.gridx++;
241:                container.add(createButton("Tantalum", gb, gbc, frame));
242:                gbc.gridx++;
243:                container.add(createButton("Tungsten", gb, gbc, frame));
244:                gbc.gridx++;
245:                container.add(createButton("Rhenium", gb, gbc, frame));
246:                gbc.gridx++;
247:                container.add(createButton("Osmium", gb, gbc, frame));
248:                gbc.gridx++;
249:                container.add(createButton("Iridium", gb, gbc, frame));
250:                gbc.gridx++;
251:                container.add(createButton("Platinum", gb, gbc, frame));
252:                gbc.gridx++;
253:                container.add(createButton("Gold", gb, gbc, frame));
254:                gbc.gridx++;
255:                container.add(createButton("Mercury", gb, gbc, frame));
256:                gbc.gridx++;
257:                container.add(createButton("Thallium", gb, gbc, frame));
258:                gbc.gridx++;
259:                container.add(createButton("Lead", gb, gbc, frame));
260:                gbc.gridx++;
261:                container.add(createButton("Bismuth", gb, gbc, frame));
262:                gbc.gridx++;
263:                container.add(createButton("Polonium", gb, gbc, frame));
264:                gbc.gridx++;
265:                container.add(createButton("Astatine", gb, gbc, frame));
266:                gbc.gridx++;
267:                container.add(createButton("Radon", gb, gbc, frame));
268:                gbc.gridx = 0;
269:                gbc.gridy++;
270:                if (showNumbering) {
271:                    container.add(createLabel("7", gb, gbc));
272:                    gbc.gridx++;
273:                }
274:                container.add(createButton("Francium", gb, gbc, frame));
275:                gbc.gridx++;
276:                container.add(createButton("Radium", gb, gbc, frame));
277:                gbc.gridx++;
278:                container.add(createButton("Actinium", gb, gbc, frame));
279:                gbc.gridx++;
280:                container.add(createButton("Unnilquadium", gb, gbc, frame));
281:                gbc.gridx++;
282:                container.add(createButton("Unnilpentium", gb, gbc, frame));
283:                gbc.gridx++;
284:                container.add(createButton("Unnilhexium", gb, gbc, frame));
285:                gbc.gridx++;
286:                container.add(createButton("Unnilseptium", gb, gbc, frame));
287:                gbc.gridx++;
288:                container.add(createButton("Unniloctium", gb, gbc, frame));
289:                gbc.gridx++;
290:                container.add(createButton("Unnilennium", gb, gbc, frame));
291:                gbc.gridx++;
292:                container.add(createButton("Ununnilium", gb, gbc, frame));
293:                if (showNumbering) {
294:                    gbc.gridx = 0;
295:                    gbc.gridy++;
296:                    Label blankline = new Label();
297:                    gb.setConstraints(blankline, gbc);
298:                    container.add(blankline);
299:                }
300:                gbc.gridx = 0;
301:                gbc.gridy++;
302:                if (showNumbering) {
303:                    container.add(createLabel("6", gb, gbc));
304:                    gbc.gridx++;
305:                }
306:                gbc.gridx += 3;
307:                container.add(createButton("Cerium", gb, gbc, frame));
308:                gbc.gridx++;
309:                container.add(createButton("Praseodymium", gb, gbc, frame));
310:                gbc.gridx++;
311:                container.add(createButton("Neodymium", gb, gbc, frame));
312:                gbc.gridx++;
313:                container.add(createButton("Promethium", gb, gbc, frame));
314:                gbc.gridx++;
315:                container.add(createButton("Samarium", gb, gbc, frame));
316:                gbc.gridx++;
317:                container.add(createButton("Europium", gb, gbc, frame));
318:                gbc.gridx++;
319:                container.add(createButton("Gadolinium", gb, gbc, frame));
320:                gbc.gridx++;
321:                container.add(createButton("Terbium", gb, gbc, frame));
322:                gbc.gridx++;
323:                container.add(createButton("Dysprosium", gb, gbc, frame));
324:                gbc.gridx++;
325:                container.add(createButton("Holmium", gb, gbc, frame));
326:                gbc.gridx++;
327:                container.add(createButton("Erbium", gb, gbc, frame));
328:                gbc.gridx++;
329:                container.add(createButton("Thulium", gb, gbc, frame));
330:                gbc.gridx++;
331:                container.add(createButton("Ytterbium", gb, gbc, frame));
332:                gbc.gridx++;
333:                container.add(createButton("Lutetium", gb, gbc, frame));
334:                gbc.gridx = 0;
335:                gbc.gridy++;
336:                if (showNumbering) {
337:                    container.add(createLabel("7", gb, gbc));
338:                    gbc.gridx++;
339:                }
340:                gbc.gridx += 3;
341:                container.add(createButton("Thorium", gb, gbc, frame));
342:                gbc.gridx++;
343:                container.add(createButton("Protactinium", gb, gbc, frame));
344:                gbc.gridx++;
345:                container.add(createButton("Uranium", gb, gbc, frame));
346:                gbc.gridx++;
347:                container.add(createButton("Neptunium", gb, gbc, frame));
348:                gbc.gridx++;
349:                container.add(createButton("Plutonium", gb, gbc, frame));
350:                gbc.gridx++;
351:                container.add(createButton("Americium", gb, gbc, frame));
352:                gbc.gridx++;
353:                container.add(createButton("Curium", gb, gbc, frame));
354:                gbc.gridx++;
355:                container.add(createButton("Berkelium", gb, gbc, frame));
356:                gbc.gridx++;
357:                container.add(createButton("Californium", gb, gbc, frame));
358:                gbc.gridx++;
359:                container.add(createButton("Einsteinium", gb, gbc, frame));
360:                gbc.gridx++;
361:                container.add(createButton("Fermium", gb, gbc, frame));
362:                gbc.gridx++;
363:                container.add(createButton("Mendelevium", gb, gbc, frame));
364:                gbc.gridx++;
365:                container.add(createButton("Nobelium", gb, gbc, frame));
366:                gbc.gridx++;
367:                container.add(createButton("Lawrencium", gb, gbc, frame));
368:            }
369:
370:            private static Label createLabel(String text, GridBagLayout gb,
371:                    GridBagConstraints gbc) {
372:                Label label = new Label(text, Label.CENTER);
373:                gb.setConstraints(label, gbc);
374:                return label;
375:            }
376:
377:            private static Button createButton(String elemName,
378:                    GridBagLayout gb, GridBagConstraints gbc, Frame frame) {
379:                Element elem = JSci.chemistry.PeriodicTable
380:                        .getElement(elemName);
381:                if (elem == null)
382:                    return null;
383:                Button but = new Button(elem.toString());
384:                if (elem instanceof  AlkaliMetal)
385:                    but.setBackground(Color.cyan);
386:                else if (elem instanceof  AlkaliEarthMetal)
387:                    but.setBackground(purple);
388:                else if (elem instanceof  NonMetal)
389:                    but.setBackground(Color.green);
390:                else if (elem instanceof  TransitionMetal)
391:                    but.setBackground(Color.orange);
392:                else if (elem instanceof  RareEarthMetal)
393:                    but.setBackground(Color.red);
394:                else if (elem instanceof  Halogen)
395:                    but.setBackground(Color.yellow);
396:                else if (elem instanceof  NobleGas)
397:                    but.setBackground(Color.pink);
398:                but.addActionListener(new ButtonAdapter(frame, elem));
399:                gb.setConstraints(but, gbc);
400:                return but;
401:            }
402:
403:            static class ButtonAdapter implements  ActionListener {
404:                private final Frame owner;
405:                private final Element element;
406:
407:                public ButtonAdapter(Frame f, Element e) {
408:                    owner = f;
409:                    element = e;
410:                }
411:
412:                public void actionPerformed(ActionEvent evt) {
413:                    new InfoDialog(owner, element);
414:                }
415:            }
416:
417:            static class InfoDialog extends Dialog {
418:                private void displayNumber(double x) {
419:                    if (x == x)
420:                        add(new Label(String.valueOf(x)));
421:                    else
422:                        /* NaN */
423:                        add(new Label("Unknown"));
424:                }
425:
426:                private void displayNumber(double x, String units) {
427:                    if (x == x)
428:                        add(new Label(String.valueOf(x) + ' ' + units));
429:                    else
430:                        /* NaN */
431:                        add(new Label("Unknown"));
432:                }
433:
434:                public InfoDialog(Frame parent, Element e) {
435:                    super (parent, e.getName());
436:                    addWindowListener(new WindowAdapter() {
437:                        public void windowClosing(WindowEvent evt) {
438:                            dispose();
439:                        }
440:                    });
441:                    setLayout(new GridLayout(11, 2));
442:                    add(new Label("Atomic Number"));
443:                    add(new Label(String.valueOf(e.getAtomicNumber())));
444:                    add(new Label("Mass Number"));
445:                    add(new Label(String.valueOf(e.getMassNumber())));
446:                    add(new Label("Density"));
447:                    displayNumber(e.getDensity(), "g/cm^3");
448:                    add(new Label("Boiling Point"));
449:                    displayNumber(e.getBoilingPoint(), "K");
450:                    add(new Label("Melting Point"));
451:                    displayNumber(e.getMeltingPoint(), "K");
452:                    add(new Label("Atomic Radius"));
453:                    displayNumber(e.getAtomicRadius());
454:                    add(new Label("Covalent Radius"));
455:                    displayNumber(e.getCovalentRadius());
456:                    add(new Label("Electronegativity"));
457:                    displayNumber(e.getElectronegativity());
458:                    add(new Label("Specific Heat"));
459:                    displayNumber(e.getSpecificHeat());
460:                    add(new Label("Electrical Conductivity"));
461:                    displayNumber(e.getElectricalConductivity());
462:                    add(new Label("Thermal Conductivity"));
463:                    displayNumber(e.getThermalConductivity());
464:                    setDefaultSize(this , 250, 250);
465:                    setVisible(true);
466:                }
467:            }
468:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.