wlahmad بتاريخ: 13 يناير 2007 تقديم بلاغ مشاركة بتاريخ: 13 يناير 2007 برنامج يظهر من خلاله كيفية التعامل مع الإظهارات في البرامج ..كما في الصور التالية:الكود هو التالي:- import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; import java.beans.*; public class MyHoroscope extends JFrame { Toolkit tk; //for getting the toolkit Dimension dim; //for getting the screen resolution JMenuBar menuBar; JMenu menuFile, menuHelp, menuView; JMenuItem itemShow, itemReset, itemExit, itemAbout, itemHelp, itemMetal, itemMotif, itemWindows; JPanel panelHead, panelHead0, panelHead1; JLabel lblName, lblBday; JTextField txtName; JButton butBday; GridBagConstraints gbc; //myCalendar calendar; public MyHoroscope() { super("Leo's Fortune Teller"); menuBar = new JMenuBar(); setJMenuBar(menuBar); menuFile = new JMenu("File"); menuFile.setMnemonic('F'); itemShow = new JMenuItem("Show Me"); itemReset = new JMenuItem("Reset"); itemExit = new JMenuItem("Exit"); itemShow.setMnemonic('S'); itemReset.setMnemonic('R'); itemExit.setMnemonic('X'); menuFile.add(itemShow); menuFile.add(itemReset); menuFile.addSeparator(); menuFile.add(itemExit); menuView = new JMenu("View"); menuView.setMnemonic('V'); itemMetal = new JMenuItem("Metal"); itemMotif = new JMenuItem("Motifs"); itemWindows = new JMenuItem("Windows"); itemMetal.setMnemonic('M'); itemMotif.setMnemonic('O'); itemWindows.setMnemonic('W'); itemMetal.setActionCommand("metal"); itemMotif.setActionCommand("motif"); itemWindows.setActionCommand("windows"); itemMetal.addActionListener(lookandfeel); itemMotif.addActionListener(lookandfeel); itemWindows.addActionListener(lookandfeel); menuView.add(itemMetal); menuView.add(itemMotif); menuView.add(itemWindows); menuHelp = new JMenu("Help"); menuHelp.setMnemonic('H'); itemAbout = new JMenuItem("About"); itemHelp = new JMenuItem("Help"); itemAbout.setMnemonic('A'); itemHelp.setMnemonic('H'); menuHelp.add(itemAbout); menuHelp.add(itemHelp); menuBar.add(menuFile); menuBar.add(menuView); menuBar.add(menuHelp); getContentPane().add(header()); //getContentPane().add(body()); tk = this.getToolkit(); dim = tk.getScreenSize(); setBounds(dim.width/4, dim.height/4, 420, 340); setResizable(false); show(); } protected JPanel header() { panelHead = new JPanel(); panelHead.setLayout(new FlowLayout()); panelHead0 = new JPanel(); panelHead0.setLayout(new BorderLayout()); panelHead1 = new JPanel(); panelHead1.setLayout(new GridLayout(2,2)); gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; lblName = new JLabel("Enter your Name:"); lblBday = new JLabel("Enter your Birthday:"); butBday = new JButton("Click Here!"); butBday.addActionListener(months); txtName = new JTextField("",15); panelHead1.add(lblName); panelHead1.add(txtName); panelHead1.add(lblBday); panelHead1.add(butBday); panelHead0.add(panelHead1, BorderLayout.CENTER); panelHead.add(panelHead0); return panelHead; } ActionListener lookandfeel = new ActionListener(){ public void actionPerformed(ActionEvent ae){ Object source = ae.getActionCommand(); String plaf = ""; if (source == "metal") plaf = "javax.swing.plaf.metal.MetalLookAndFeel"; else if (source == "motif") plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; else if (source == "windows") plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; try { UIManager.setLookAndFeel(plaf); SwingUtilities.updateComponentTreeUI(MyHoroscope.this); } catch (Exception e) { } } }; ActionListener months = new ActionListener() { public void actionPerformed(ActionEvent ae) { //calendar = new myCalendar(); //calendar.show(); } }; public static void main(String args[]) { MyHoroscope horoscope = new MyHoroscope(); } } اقتباس رابط هذا التعليق شارك المزيد من خيارات المشاركة
Recommended Posts
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.