import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
public class MyJFrame extends JFrame implements ActionListener,MouseListener{
private JTextField tfdname;
private JTextField tfdpwd;
JButton btn1,btn2,btn3,btn4,btn5,btn6;
public MyJFrame(String str){
setTitle( str);
setLocation(300,200);
setSize(400, 370);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setBackground(Color.red);
getContentPane().setLayout(new FlowLayout(FlowLayout.RIGHT,5,20));
JLabel lb1=new JLabel("姓名");
tfdname= new JTextField(22);
add(lb1);
add(tfdname);
JLabel lb2=new JLabel("密码");
tfdpwd =new JTextField(22);
add(lb2);
add(tfdpwd);

btn1=new JButton("MOVE");
btn2=new JButton("退出");
add(btn1);
add(btn2);

btn1.addActionListener(this);
btn2.addActionListener(this);

btn3=new JButton("JOptionPane");
add(btn3);
btn3.addActionListener(this);

btn4=new JButton("JOptionPane2");
add(btn4);
btn4.addActionListener(this);

btn5=new JButton("JOptionPane3");
add(btn5);
btn5.addActionListener(this);

btn6=new JButton("JColorChoose");
add(btn6);
btn6.addActionListener(this);

addMenu();
addPopMenu();

String datas[][]={{"70","65","80","90"},
{"69","45","90","80"},
{"89","78","56","67"},
{"89","58","50","40"}
};

String titles[]={"math","language","art","programe"};
JTable table=new JTable(datas,titles);
table.setSize(300,200);
this.getContentPane().add(new JScrollPane(table));
setVisible(true);
}
private JPopupMenu pMenu=null;
private void addPopMenu() {
pMenu =new JPopupMenu();
JMenuItem miCopy=new JMenuItem("复制");
JMenuItem miCut=new JMenuItem("剪切");
JMenuItem miPaste=new JMenuItem("复制");
pMenu.add(miCopy);
pMenu.add(miCut);
pMenu.add(miPaste);

tfdname.add(pMenu);
tfdname. addMouseListener(this);

miCopy.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
tfdname.copy();
}
});

miCut.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
tfdname.cut();
}
});
}

private void addMenu() {
JMenuBar bar = new JMenuBar();
this.setJMenuBar(bar);
JMenu menuFile=new JMenu("文件");
bar.add(menuFile );
JMenuItem menuNew=new JMenuItem("新建");
menuFile.add(menuNew);
JMenuItem menuOpen=new JMenuItem("打开");
menuFile.add(menuOpen);
menuFile.addSeparator();
JMenuItem menuExit=new JMenuItem("退出");
menuExit.setActionCommand("e");
menuFile.add(menuExit);

JMenu menuEdit=new JMenu("编辑");
bar.add(menuEdit);
JMenuItem miCopy=new JMenuItem("复制");
menuEdit.add(miCopy);
JMenuItem miCut=new JMenuItem("剪切");
menuEdit.add(miCut);
JMenuItem miPaste=new JMenuItem("粘贴");
menuEdit.add(miPaste);
JCheckBoxMenuItem miSel=new JCheckBoxMenuItem("选择",true);
menuEdit.add(miSel);
AbstractButton miExit;
menuExit.addActionListener(this);
}
public static void main(String args[])
{
new MyJFrame("湖南城市学院");
}

public void actionPerformed(ActionEvent e) {
if(e.getSource()==btn1){
String text=tfdname.getText();
tfdpwd.setText(text);
tfdname.setText("");
}
if(e.getSource()==btn2){
System.exit(0);
}
if(e.getSource()==btn3){
int i=JOptionPane.showConfirmDialog(this ,"请确认--城院");
if(i==JOptionPane.CANCEL_OPTION){
System.out.println("取消");
}
else if(i==JOptionPane.NO_OPTION){
System.out.println("否");
}
else if(i==JOptionPane.OK_OPTION){
System.out.println("是");
}

}
if(e.getSource()==btn4){
JOptionPane.showMessageDialog(this, "我的提示信息--城院");
}
if(e.getSource()==btn5){
String str=JOptionPane.showInputDialog("请输入你的姓名:" );
System.out.println("你输入的是:"+str);
}
if(e.getSource()==btn6){
Color c=JColorChooser.showDialog( this, "请选择颜色",Color.CYAN);
this.getContentPane().setBackground(c);
}
if(e.getActionCommand().equals( "e")){
System.exit(0);
}
}
public void mouseClicked(MouseEvent e) {
if(e.getModifiers()==MouseEvent.BUTTON2_MASK){
pMenu.show(tfdname,e.getX(),e.getY());

}

}

public void mousePressed(MouseEvent e) {

}

@Override
public void mouseReleased(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent e) {

}

@Override
public void mouseExited(MouseEvent e) {

}

}

最新文章

  1. vs2013 手动生成webservice代理类wsdl
  2. 烂泥:Postfix邮件服务器搭建之软件安装与配置
  3. flume+sparkStreaming实例 实时监控文件demo
  4. [Python Day5] 常用模块
  5. POJ 1182 食物链(带权并查集)
  6. js方法类库封装的简易示例
  7. platform机制
  8. 利用Python读取json数据并求数据平均值
  9. Linux下select函数的使用
  10. swfobject.js的简单配置
  11. 第5章 不要让线程成为脱缰的野马(Keeping your Threads on Leash) ---线程优先权(Thread priority)
  12. ArcticCore重构-VALIDATE_%
  13. Unsupported major.minor version 52.0解决办法
  14. MATLAB中a(:)和." ' "," ' "
  15. Oracle12c 性能优化攻略:攻略1-3: 匹配表类型与业务需求
  16. 快速测试方法——JUnit
  17. 【持续更新】 | OpenCV 学习笔记
  18. HDMI传输原理:TMDS
  19. Java - TreeMap源码解析 + 红黑树
  20. Linux下用netstat查看网络状态、端口状态

热门文章

  1. SPSS数据分析—配对Logistic回归模型
  2. struts2学习笔记之六:struts2的Action访问ServletAPI的几种方式
  3. stm32cube--通用定时器--输入捕获
  4. ASP.NET 5中的静态文件处理
  5. bzoj3304 [Shoi2005]带限制的最长公共子序列
  6. 光流算法:灰度恒常约束,LK算法,HS算法
  7. asp.net mvc 从数据库中读取图片的实现代码
  8. 【Cocos2d-x】 HttpClient 网络通信(Http)的简单应用
  9. SRM 403(1-250pt, 1-500pt)
  10. css3实现图片遮罩效果鼠标hover以后出现文字
  11. CSS中的特殊性、继承、层叠
  12. js日期天数差
  13. 【Android】又一个Gank客户端来啦
  14. DirectX 11---从空间变换来看3D场景如何转化到2D屏幕
  15. 设计模式的征途—20.备忘录(Memento)模式
  16. microsoft.jet.oledb.4.0 未注册
  17. python导入import
  18. c c++ 函数不要返回局部变量的指针
  19. Mybatis使用MySQL模糊查询时输入中文检索不到结果怎么办--转自http://www.jb51.net/article/88236.htm
  20. Ubuntu14.04搭建Android O编译环境