JDesktopPane demo : InternalFrame « Swing JFC « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
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 » Swing JFC » InternalFrameScreenshots 
JDesktopPane demo
JDesktopPane demo
 
/*
Definitive Guide to Swing for Java 2, Second Edition
By John Zukowski     
ISBN: 1-893115-78-X
Publisher: APress
*/

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Polygon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Examples {
  public static void main(String args[]) {

    JFrame frame = new JFrame("Example Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(01));

    JFrame frame2 = new JFrame("Desktop");
    final JDesktopPane desktop = new JDesktopPane();
    frame2.getContentPane().add(desktop);
    JButton pick = new JButton("Pick");
    pick.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        System.out.println("Hi");
      }
    });
    frame2.getContentPane().add(pick, BorderLayout.SOUTH);

    JButton messagePopup = new JButton("Message");
    contentPane.add(messagePopup);
    messagePopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();
        JOptionPane.showMessageDialog(source, "Printing complete");
        JOptionPane.showInternalMessageDialog(desktop,
            "Printing complete");
      }
    });

    JButton confirmPopup = new JButton("Confirm");
    contentPane.add(confirmPopup);
    confirmPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();
        JOptionPane.showConfirmDialog(source, "Continue printing?");
        JOptionPane.showInternalConfirmDialog(desktop,
            "Continue printing?");
      }
    });

    JButton inputPopup = new JButton("Input");
    contentPane.add(inputPopup);
    inputPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();
        JOptionPane.showInputDialog(source, "Enter printer name:");
        // Moons of Neptune
        String smallList[] "Naiad""Thalassa""Despina",
            "Galatea""Larissa""Proteus""Triton""Nereid" };
        JOptionPane.showInternalInputDialog(desktop, "Pick a printer",
            "Input", JOptionPane.QUESTION_MESSAGE, null, smallList,
            "Triton");
        // Moons of Saturn - includes two provisional designations to
        // make 20
        String bigList[] "Pan""Atlas""Prometheus""Pandora",
            "Epimetheus""Janus""Mimas""Enceladus""Tethys",
            "Telesto""Calypso""Dione""Helene""Rhea",
            "Titan""Hyperion""Iapetus""Phoebe""S/1995 S 2",
            "S/1981 S 18" };
        //        Object saturnMoon = JOptionPane.showInputDialog(source, "Pick
        // a printer", "Input", JOptionPane.QUESTION_MESSAGE, null,
        // bigList, "Titan");
        Object saturnMoon = JOptionPane.showInputDialog(source,
            "Pick a printer""Input",
            JOptionPane.QUESTION_MESSAGE, null, bigList, null);
        System.out.println("Saturn Moon: " + saturnMoon);
      }
    });

    JButton optionPopup = new JButton("Option");
    contentPane.add(optionPopup);
    optionPopup.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
        Component source = (ComponentactionEvent.getSource();

        Icon greenIcon = new DiamondIcon(Color.green);
        Icon redIcon = new DiamondIcon(Color.red);
        Object iconArray[] greenIcon, redIcon };
        JOptionPane.showOptionDialog(source, "Continue printing?",
            "Select an Option", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, iconArray,
            iconArray[1]);

        Icon blueIcon = new DiamondIcon(Color.blue);
        Object stringArray[] "Do It""No Way" };
        JOptionPane.showInternalOptionDialog(desktop,
            "Continue printing?""Select an Option",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray,
            stringArray[0]);
      }
    });

    frame.setSize(300200);
    frame.setVisible(true);
    frame2.setSize(300200);
    frame2.setVisible(true);
  }
}

class DiamondIcon implements Icon {
  private Color color;

  private boolean selected;

  private int width;

  private int height;

  private Polygon poly;

  private static final int DEFAULT_WIDTH = 10;

  private static final int DEFAULT_HEIGHT = 10;

  public DiamondIcon(Color color) {
    this(color, true, DEFAULT_WIDTH, DEFAULT_HEIGHT);
  }

  public DiamondIcon(Color color, boolean selected) {
    this(color, selected, DEFAULT_WIDTH, DEFAULT_HEIGHT);
  }

  public DiamondIcon(Color color, boolean selected, int width, int height) {
    this.color = color;
    this.selected = selected;
    this.width = width;
    this.height = height;
    initPolygon();
  }

  private void initPolygon() {
    poly = new Polygon();
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    poly.addPoint(0, halfHeight);
    poly.addPoint(halfWidth, 0);
    poly.addPoint(width, halfHeight);
    poly.addPoint(halfWidth, height);
  }

  public int getIconHeight() {
    return height;
  }

  public int getIconWidth() {
    return width;
  }

  public void paintIcon(Component c, Graphics g, int x, int y) {
    g.setColor(color);
    g.translate(x, y);
    if (selected) {
      g.fillPolygon(poly);
    else {
      g.drawPolygon(poly);
    }
    g.translate(-x, -y);
  }
}

           
         
  
Related examples in the same category
1. A quick demonstration of setting up an internal frame in an applicationA quick demonstration of setting up an internal frame in an application
2. A simple extension of the JInternalFrame class that contains a list
3. Working with Internal Frames within a Desktop
4. Internal Frames DemoInternal Frames Demo
5. InternalFrame TestInternalFrame Test
6. JDesktopPane Cascade DemoJDesktopPane Cascade Demo
7. Java X WindowsJava X Windows
8. Desktop Manager DemoDesktop Manager Demo
9. Internal Frame Listener Demo Internal Frame Listener Demo
10. Layered Pane DemoLayered Pane Demo
11. LayeredPane Demo 2: Custom MDILayeredPane Demo 2: Custom MDI
12. LayeredPane Demo 3: Custom MDILayeredPane Demo 3: Custom MDI
13. LayeredPane Demo 4: Custom MDILayeredPane Demo 4: Custom MDI
14. Implements InternalFrameListenerImplements InternalFrameListener
15. InternalFrame demoInternalFrame demo
16. InternalFrameEvent DemoInternalFrameEvent Demo
17. A few interesting things using JInternalFrames, JDesktopPane, and DesktopManagerA few interesting things using JInternalFrames, JDesktopPane, and DesktopManager
18. A quick setting up an Internal Frame in an applicationA quick setting up an Internal Frame in an application
19. Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2Interesting things using JInternalFrames, JDesktopPane, and DesktopManager 2
20. Make a JInternalFrame a tool window
21. Move JInternalFrame To Front
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.