Engineeringserver.com

A community for computer science students & developers about software development, game development, game design, games, anime preview & reviews and more!


How to write a JToolBar application with Java

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5 out of 5)
Loading ... Loading ...
381 views

Here’s a small demo I wrote that shows you how to use the Java JToolBar. The toolbar doesn’t do a lot except for showing a message when the user clicks one of the toolbar items.

Screenshot:

(more…)


Your Ad Here

The Plain Wrap Auto Parts Company assignment

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
Loading ... Loading ...
235 views

Someone asked me to write an application that:

• Use an array to store the data for the different brands.
• Must have 4 additional index positions available for data entry so that I may be able to add
• Must ensure that PR or Plain Wrap is not duplicated in data entry
• Cannot use scanner
• You may choose to use 2 dimensional array (one class needed) or object of array(two classes needed)

Output:
• You will need to display the plain wrap number chosen and the corresponding Brands for that particular part.

So here it is:

(more…)


Your Ad Here

How to write simple captcha software with Java

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...
1,018 views

This is a demo I wrote earlier today to show you how you can write captcha software with Java. The application is really basic and currently only supports numbers but the code can be modified easily to support text. I’ll probably add this features later when i have the time to code it. Until then, here’s the JCaptcha code that works with numbers:

(more…)


Your Ad Here

How to create and use JTree’s

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...
1,289 views

A small demo I wrapped up that shows you how to use a JTree. The demo shows a JTree and a message of the selected item on the bottom of the JFrame.

JAVA:
  1. import java.awt.Color;
  2. import javax.swing.JFrame;
  3. import javax.swing.JLabel;
  4. import javax.swing.JTree;
  5. import javax.swing.event.TreeSelectionEvent;
  6. import javax.swing.event.TreeSelectionListener;
  7. import javax.swing.tree.DefaultMutableTreeNode;
  8. import javax.swing.tree.TreeSelectionModel;
  9. public class TreeDemo extends JFrame implements TreeSelectionListener{
  10. JTree tree;
  11. DefaultMutableTreeNode root, child1,child2,child3, item1,item2;
  12. JLabel message;
  13. public TreeDemo(){
  14. setTitle("TreeDemo :: www.engineeringserver.com");
  15. getContentPane().setLayout(null);
  16. root = new DefaultMutableTreeNode("root");
  17. child1 = new DefaultMutableTreeNode("Child1");
  18. child2 = new DefaultMutableTreeNode("Child2");
  19. child3 = new DefaultMutableTreeNode("Child3");
  20. item1 = new DefaultMutableTreeNode("item1");
  21. item2 = new DefaultMutableTreeNode("item2");
  22. root.add(child1);
  23. root.add(child2);
  24. root.add(child3);
  25. child2.add(item1);
  26. child2.add(item2);
  27. tree = new JTree(root);
  28. tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  29. expandAll(tree);
  30. tree.addTreeSelectionListener(this);
  31. tree.setBounds(0,0,400,200);
  32. message = new JLabel("Selected: ");
  33. message.setBounds(0,200,200,20);
  34. add(tree);
  35. add(message);
  36. setLocationRelativeTo(null);
  37. setResizable(false);
  38. setSize(400,250);
  39. setVisible(true);
  40. }
  41. public static void main(String[] args){
  42. new TreeDemo();
  43. }
  44. public void valueChanged(TreeSelectionEvent e) {
  45. DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
  46. Object nodeInfo = node.getUserObject();
  47. message.setText("Selected: " + nodeInfo);
  48. }
  49. public void expandAll(JTree tree) {
  50. int totalElements = 0;
  51. while (totalElements <tree.getRowCount()) {
  52. tree.expandRow(totalElements);
  53. totalElements++;
  54. }
  55. }
  56. }


Your Ad Here