• java基础学习之 消息对话款


     1 package Dome;
     2 import java.awt.event.*;
     3 import java.awt.*;
     4 import javax.swing.*;
     5 
     6 public class WindowMess extends JFrame implements ActionListener
     7 {
     8    JTextField inputEnglish ;
     9    JTextArea show ;
    10    String regex = "[a-zZ-Z]+";
    11    WindowMess()
    12    {
    13        inputEnglish = new JTextField(22);
    14        inputEnglish.addActionListener(this);
    15        show = new JTextArea();
    16        add(inputEnglish,BorderLayout.NORTH);  //默认布局
    17        add(show,BorderLayout.CENTER);
    18        setVisible(true);
    19        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    20    }
    21    public void actionPerformed(ActionEvent e)
    22    {
    23       if(e.getSource()==inputEnglish)
    24       {
    25         String str=inputEnglish.getText();
    26         if(str.matches(regex))
    27             show.append(str+"");
    28       else
    29       {
    30         //弹出“警告”消息对话框
    31           JOptionPane.showMessageDialog(this, "8 干呀6","消息对话款",JOptionPane.WARNING_MESSAGE);
    32           inputEnglish.setText(null);
    33       } 
    34      }
    35    }
    36    
    37 }
    WindowMess.java
     1 package Dome;
     2 
     3 public class example_1 {
     4     public static void main(String args[])
     5     {
     6         WindowMess win = new WindowMess();
     7         win.setTitle("带消息对话框的窗口");
     8         win.setBounds(80,90,200,300);
     9     }
    10 }
    Main

    颜色对话框

    创建一个颜色对话框 

    public static Color showDialog( Component  component ,String title ,Color initialColor)
    /*
    创建一个有模式的颜色对话框,其中参数component 指定颜色对话框可见时的位置,颜色对话框在参数,component 指定的组件的正前方显示出来,如果component为null,颜色对话框在屏幕的正前方显示出来。title指定对话框的标题,initialColor指定颜色对话框返回的初始值。用户通过颜色对话框选择颜色后,如果单击“确定”按钮,那么颜色对象,如果单击“撤销”按钮或者关闭图标,那么颜色对话框将消失,showDialog()方法返回null
    */

     1 package tes;
     2 import java.awt.*;
     3 import java.awt.event.*;
     4 import javax.swing.*;
     5 
     6 public class WindowColor extends JFrame implements ActionListener
     7 {
     8   JButton button ;
     9   WindowColor()
    10   {
    11     button = new JButton("打开颜色对话框");
    12     button.addActionListener(this);
    13     setLayout(new FlowLayout());
    14     add(button);
    15     setVisible(true);
    16     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    17   }
    18   public void actionPerformed(ActionEvent e)
    19   {
    20       Color newColor = JColorChooser.showDialog(this,"调色板",getContentPane().getBackground());
    21       if(newColor!=null)  //将this所指的颜色传送给newColor.......
    22           getContentPane().setBackground(newColor);   //重置背景颜色
    23   }
    24 }
    example
     1 package tes;
     2 
     3 public class example {
     4   public static void main(String args[])
     5   {
     6     WindowColor win = new WindowColor();
     7     win.setTitle("带颜色对话框的窗口");
     8     win.setBounds(80, 90, 200,300);
     9   }
    10 }
    Main

    效果图:

  • 相关阅读:
    从运维角度浅谈 MySQL 数据库优化
    好的架构不是设计出来的,而是演进出来的
    京东咚咚架构演进
    大型网站的架构
    MySQL开发规范
    MySQL 5.6的72个新特性(译)
    MySQL数据库运维的五大指标
    MySQL5.0、5.1、5.5、5.6功能进化
    MySQL各版本的区别
    ajax该什么时候用
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3853612.html
Copyright © 2020-2023  润新知