zoukankan      html  css  js  c++  java
  • 界面制作小例

    import  java.awt.*;
    import  java.awt.event.*;
    import  java.applet.*;
    import  javax.swing.*;
    public class xuexingyuxingge  implements  ActionListener {
    JMenuItem    jm1,jm2;
    static  JFrame  f;
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    f=new  JFrame("血型与性格");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    xuexingyuxingge   a1=new  xuexingyuxingge();                          //创建对象
    f.setJMenuBar(a1.init());
    f.setSize(300,200);
    f.show();
        }
    
        public JMenuBar init() {
            // TODO Auto-generated method stub
            JMenuBar   menuBar=new   JMenuBar();
            JMenu  mu=new  JMenu("程  序");
            jm1=new  JMenuItem("选择血型");                                  //添加一个新的菜单命令
            mu.add(jm1);
            jm2=new  JMenuItem("退   出");
            mu.add(jm2);
            menuBar.add(mu);
            jm1.addActionListener(this);
            jm2.addActionListener(this);
            return  menuBar;
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            String  s="";
            if(e.getSource()==jm1){
                Object[]  type={"1-AB型","2-A型","3-B型","4-O型"};
                s=(String)JOptionPane.showInputDialog(f, "请选择血型", "血型与性格",JOptionPane.INFORMATION_MESSAGE,null,type,"1-AB型");
            }else{
                int  n=JOptionPane.showConfirmDialog(f, "是否要退出程序", "血型与性格",JOptionPane.OK_CANCEL_OPTION);
                if(n==JOptionPane.OK_OPTION)                        System.exit(0);
            }
            if(s.substring(0,1).equals("1"))
                JOptionPane.showMessageDialog(f, "富于知性,言辞谨慎,情感丰富,与众不同","AB血型人的人格特点",JOptionPane.INFORMATION_MESSAGE);
            if(s.substring(0,1).equals("2"))
                JOptionPane.showMessageDialog(f, "有礼貌,做事认真,善于聆听,爱好清洁","A血型人的人格特点",JOptionPane.INFORMATION_MESSAGE);
            if(s.substring(0,1).equals("3"))
                JOptionPane.showMessageDialog(f, "开朗敏捷,善于言辞,与人相处融洽","B血型人的人格特点",JOptionPane.INFORMATION_MESSAGE);
            if(s.substring(0,1).equals("4"))
                JOptionPane.showMessageDialog(f, "整洁,有魄力,思考周密,顾全大局","O血型人的人格特点",JOptionPane.INFORMATION_MESSAGE);
        }
    
    }
    在Swing中,许多类都支持对话框,例如JFileChooser.JColorChooser.JOPtionPane等。这里只介绍JFileChooser类和JOPtionPane类支持得对话框类型。
    1.JFileChooser类是为用户提供打开或储存文件等处理功能的对话框,也称为文件选择器。JFileChooser类只提供了选择文件或目录的图形用户界面,打开文件或储存文件等操作还需要添加代码。创建JFileChooser类对象的格式有以下3种。
    JFileChooser 对象名=new JFileChooser();
    JFileChooser 对象名=new JFileChooser(File currentDrictory);
    JFileChooser 对象名=new JFileChooser(File currentDritory,FileSystemView fsv);
    2.showMessageDialog()对话框用来显示对用户的提示信息,其格式为:
    showMessageDialog(Component c,Object message,String title,int messageType)
    其中,参数c为放置该对话框的组件或者容器,一般为JFrame类对象。参数message为需要向用户传达的提示信息,一般为String类型的数据。参数title为对话框的显示标题,并默认值为“消息”。参数messageType为对话框中信息的类型,其共有5个常量值分别对应不同的图标。这5个常量为ERROR_MESSAGE,INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE和PLAIN_MESSAGE,默认值为INFORMATION_MESSAGE.
    例:JOPtionPane.showMessageDialog(f
    rame,"谢谢您的参与!","收视率调查",JoptionPane.INFORMATION_MESSAGE);
  • 相关阅读:
    leetcode 48. Rotate Image
    leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点) 、26/80. Remove Duplicates from Sorted ArrayI、II
    leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes
    leetcode 58. Length of Last Word
    安卓操作的一些问题解决
    leetcode 378. Kth Smallest Element in a Sorted Matrix
    android studio Gradle Build速度加快方法
    禁用gridview,listview回弹或下拉悬停
    Android Studio找不到FragmentActivity类
    安卓获取ListView、GridView等滚动的距离(高度)
  • 原文地址:https://www.cnblogs.com/CUI2014/p/5293942.html
Copyright © 2011-2022 走看看