Please click on ads

Please click on ads

Wednesday, 3 November 2021

create a payment application in java by using swing -eclipse





  1.  package test;

  2. import java.awt.Component;
  3. import java.awt.EventQueue;
  4. import java.awt.FlowLayout;
  5. import java.awt.SystemColor;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;

  10. import javax.swing.AbstractListModel;
  11. import javax.swing.BorderFactory;
  12. import javax.swing.DefaultComboBoxModel;
  13. import javax.swing.JButton;
  14. import javax.swing.JCheckBox;
  15. import javax.swing.JComboBox;
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JList;
  19. import javax.swing.JOptionPane;
  20. import javax.swing.JPanel;
  21. import javax.swing.JPopupMenu;
  22. import javax.swing.JRadioButton;
  23. import javax.swing.JTextArea;
  24. import javax.swing.border.Border;
  25. import javax.swing.border.EmptyBorder;
  26. import javax.swing.border.TitledBorder;

  27. public class payment_1905701 {

  28. private JFrame frame;

  29. /**
  30. * Launch the application.
  31. */
  32. public static void main(String[] args) {
  33. EventQueue.invokeLater(new Runnable() {
  34. public void run() {
  35. try {
  36. payment_1905701 window = new payment_1905701();
  37. window.frame.setVisible(true);
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. });
  43. }

  44. /**
  45. * Create the application.
  46. */
  47. public payment_1905701() {

  48. setTitle("Roll No:1905701 Payment Application\r\n");
  49. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  50. setBounds(100, 100, 480, 397);
  51. JPanel p2 = new JPanel();
  52. p2.setBackground(SystemColor.controlHighlight);
  53. p2.setBorder(new EmptyBorder(5, 5, 5, 5));
  54. setContentPane(p2);
  55. p2.setLayout(null);

  56. JPanel p1 = new JPanel();
  57. p1.setToolTipText("");
  58. p1.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
  59. p1.setBackground(SystemColor.controlHighlight);
  60. p1.setBounds(0, 11, 464, 47);
  61. p2.add(p1);
  62. p1.setLayout(null);
  63. Border b = BorderFactory.createTitledBorder("Billing");
  64. p1.setBorder(b);
  65. JRadioButton cl = new JRadioButton("Card Number");
  66. cl.setBounds(33, 17, 109, 23);
  67. p1.add(cl);
  68. JRadioButton cl1 = new JRadioButton("Bill Customer");
  69. cl1.setBounds(159, 17, 109, 23);
  70. p1.add(cl1);
  71. JLabel lblNewLabel = new JLabel("Card Type");
  72. lblNewLabel.setBounds(23, 92, 72, 20);
  73. p2.add(lblNewLabel);
  74. JPanel panel_1 = new JPanel();
  75. panel_1.setBounds(142, 81, 282, 65);
  76. p2.add(panel_1);
  77. panel_1.setLayout(null);
  78. JList list = new JList();
  79. list.setModel(new AbstractListModel() {
  80. String[] values = new String[] {"Visa", "Master Card", "American Express"};
  81. public int getSize() {
  82. return values.length;
  83. }
  84. public Object getElementAt(int index) {
  85. return values[index];
  86. }
  87. });
  88. list.setBounds(0, 0, 179, 54);
  89. panel_1.add(list);
  90. JLabel lblNewLabel_1 = new JLabel("Card Number");
  91. lblNewLabel_1.setBounds(23, 177, 72, 20);
  92. p2.add(lblNewLabel_1);
  93. JTextArea t = new JTextArea();
  94. t.setBounds(142, 175, 282, 22);
  95. p2.add(t);
  96. JLabel lblNewLabel_2 = new JLabel("Expiration Date:");
  97. lblNewLabel_2.setBounds(23, 218, 98, 20);
  98. p2.add(lblNewLabel_2);
  99. JPanel panel_2 = new JPanel();
  100. panel_2.setBackground(SystemColor.controlHighlight);
  101. panel_2.setBounds(0, 249, 464, 47);
  102. p2.add(panel_2);
  103. panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  104. JCheckBox v = new JCheckBox("Varified");
  105. panel_2.add(v);
  106. JButton accept = new JButton("Accept");
  107. accept.addActionListener(new ActionListener() {
  108. public void actionPerformed(ActionEvent e) {
  109. JOptionPane.showConfirmDialog(accept, this, "accept", 0);
  110. accept.addActionListener(new ActionListener() {
  111.             @Override
  112.             public void actionPerformed(final ActionEvent e) {
  113.                 String str = " ";
  114.                 String yv = "";
  115.                 if (cl.isSelected()) {
  116.                     if (cl1.isSelected()) {
  117.                         yv = "Card has been Verified";
  118.                     }
  119.                     else {
  120.                         yv = "Card has been not verified";
  121.                     }
  122.                     JComboBox mon;
  123. JComboBox year;
  124. str = "Bill " + list.getSelectedValue() + System.lineSeparator() + "Number+" + t.getText() + System.lineSeparator() + "Expiary date: " + mon.getSelectedItem() +","+ year.getSelectedItem() + System.lineSeparator();
  125.                 }
  126.                 else if (list.isSelected()) {
  127.                     str = "Customer will be billed";
  128.                 }
  129.                 else {
  130.                     str = "Please Choose a Billing Option";
  131.                 }
  132. //                 JOptionPane.showMessageDialog(PaymentApp_1905698.this, String.valueOf(str + yv);
  133.             }
  134.         });
  135. }
  136. });
  137. accept.setForeground(SystemColor.windowText);
  138. accept.setBackground(SystemColor.textHighlight);
  139. accept.setBounds(257, 324, 89, 23);
  140. p2.add(accept);
  141. // jf.setTitle("aja");

  142. JButton exit = new JButton("Exit");
  143. exit.setBounds(365, 324, 89, 23);
  144. p2.add(exit);
  145. accept.addActionListener(new ActionListener() {
  146. public void actionPerformed(ActionEvent e) {
  147. }
  148. });
  149. JComboBox mon = new JComboBox();
  150. mon.setBackground(SystemColor.controlHighlight);
  151. mon.setModel(new DefaultComboBoxModel(new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}));
  152. mon.setBounds(152, 217, 100, 22);
  153. p2.add(mon);
  154. JComboBox year = new JComboBox();
  155. year.setBackground(SystemColor.controlHighlight);
  156. year.setModel(new DefaultComboBoxModel(new String[] {"1990", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023"}));
  157. year.setBounds(278, 217, 78, 22);
  158. p2.add(year);

  159. }
  160. private void setContentPane(JPanel p2) {
  161. // TODO Auto-generated method stub
  162. }

  163. private void setBounds(int i, int j, int k, int l) {
  164. // TODO Auto-generated method stub
  165. }

  166. private void setDefaultCloseOperation(int exitOnClose) {
  167. // TODO Auto-generated method stub
  168. }

  169. private void setTitle(String string) {
  170. // TODO Auto-generated method stub
  171. }

  172. // private void jButtonActionperformed(java.awt.event.ActionEvent evt) {
  173. // JOptionPane.showInputDialog(f, "jsdaa", "exit");
  174. //
  175. // }
  176. private static void addPopup(Component component, final JPopupMenu popup) {
  177. component.addMouseListener(new MouseAdapter() {
  178. public void mousePressed(MouseEvent e) {
  179. if (e.isPopupTrigger()) {
  180. showMenu(e);
  181. }
  182. }
  183. public void mouseReleased(MouseEvent e) {
  184. if (e.isPopupTrigger()) {
  185. showMenu(e);
  186. }
  187. }
  188. private void showMenu(MouseEvent e) {
  189. popup.show(e.getComponent(), e.getX(), e.getY());
  190. }
  191. });
  192. }


  193. /**
  194. * Initialize the contents of the frame.
  195. */
  196. private void initialize() {
  197. frame = new JFrame();
  198. frame.setBounds(100, 100, 450, 300);
  199. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  200. }

  201. }

No comments:

Post a Comment