Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. package com.utad.damp.dein.t16;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.EventQueue;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.border.EmptyBorder;
  10.  
  11. import java.awt.CardLayout;
  12. import java.awt.FlowLayout;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15.  
  16. import javax.swing.JButton;
  17. import javax.swing.SwingConstants;
  18.  
  19.  
  20. public class JFrameT16 extends JFrame {
  21.  
  22. private JPanel contentPane;
  23. private final String RED_PANEL = "Red Panel";
  24. private final String GREEN_PANEL = "Green Panel";
  25. private final String BLUE_PANEL = "Blue Panel";
  26. private CardLayout cardLayout;
  27. private JPanel panelCenter;
  28.  
  29. class MyActionListener implements ActionListener {
  30.  
  31. @Override
  32. public void actionPerformed(ActionEvent e) {
  33.  
  34.  
  35.  
  36. }
  37.  
  38. }
  39.  
  40. /**
  41. * Launch the application.
  42. */
  43. public static void main(String[] args) {
  44. EventQueue.invokeLater(new Runnable() {
  45. public void run() {
  46. try {
  47. JFrameT16 frame = new JFrameT16();
  48. frame.setVisible(true);
  49. } catch (Exception e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. });
  54. }
  55.  
  56. /**
  57. * Create the frame.
  58. */
  59. public JFrameT16() {
  60. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  61. setBounds(100, 100, 450, 300);
  62. contentPane = new JPanel();
  63. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  64. contentPane.setLayout(new BorderLayout(0, 0));
  65. setContentPane(contentPane);
  66.  
  67. JPanel panelNorth = new JPanel();
  68. contentPane.add(panelNorth, BorderLayout.NORTH);
  69. panelNorth.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  70.  
  71. JButton redButton = new JButton("Panel Rojo");
  72. redButton.setHorizontalAlignment(SwingConstants.LEFT);
  73. panelNorth.add(redButton);
  74.  
  75. JButton greenButton = new JButton("Panel Verde");
  76. panelNorth.add(greenButton);
  77.  
  78. JButton blueButton = new JButton("Panel Azul");
  79. panelNorth.add(blueButton);
  80.  
  81. panelCenter = new JPanel();
  82. contentPane.add(panelCenter, BorderLayout.CENTER);
  83.  
  84.  
  85. // CÓDICO SIN EL EDITOR GRÁFICO
  86. cardLayout = new CardLayout();
  87. panelCenter.setLayout(cardLayout);
  88.  
  89. JPanel redPanel = new JPanel();
  90. redPanel.setBackground(Color.red);
  91. JPanel greenPanel = new JPanel();
  92. greenPanel.setBackground(Color.green);
  93. JPanel bluePanel = new JPanel();
  94. bluePanel.setBackground(Color.blue);
  95.  
  96. panelCenter.add(redPanel, RED_PANEL);
  97. panelCenter.add(greenPanel, GREEN_PANEL);
  98. panelCenter.add(bluePanel, BLUE_PANEL);
  99.  
  100.  
  101.  
  102. redButton.addActionListener(new ActionListener() {
  103.  
  104. @Override
  105. public void actionPerformed(ActionEvent e) {
  106. cardLayout.show(panelCenter, RED_PANEL);
  107. }
  108. });
  109.  
  110. greenButton.addActionListener(new ActionListener() {
  111.  
  112. @Override
  113. public void actionPerformed(ActionEvent e) {
  114. cardLayout.show(panelCenter, GREEN_PANEL);
  115. }
  116. });
  117.  
  118. blueButton.addActionListener(new ActionListener() {
  119.  
  120. @Override
  121. public void actionPerformed(ActionEvent e) {
  122. cardLayout.show(panelCenter, BLUE_PANEL);
  123. }
  124. });
  125.  
  126.  
  127. }
  128.  
  129.  
  130.  
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement