A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

=================第一个文件=================
package Lianx;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Pattern;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
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.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.Graphics;
public class CardLyouta extends JFrame{
public static CardLyouta def = null;
private JFrame jf;
private JPanel jp,jp1,jp2,jp3;
private CardLayout card;
private JMenuBar jmb;
private JMenu jmu;
private JTable datetable=null;
private JMenuItem open,on,exit,biaoge;
private AddDialog jaccount,jname,jsex,jphone,jpassword;
public void init(){
jf=new JFrame();
card=new CardLayout();
jmb=new JMenuBar();
jmu=new JMenu("新建(N)");
jmu.setMnemonic(KeyEvent.VK_N);
open=new JMenuItem("打开");
on=new JMenuItem("保存");
exit=new JMenuItem("退出");
biaoge=new JMenuItem("表格");
jp=new JPanel();
jp.setLayout(card);
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jp1.add(new JLabel(new ImageIcon("2.gif")));
jp2.add(new JLabel(new ImageIcon("1.png")));
Object[] meishititle={"帐号","姓名","性别","电话","密码"};
Object[][] meishiDate={
new Object[]{2455443,"张速度","男","1569841525","156235ddf"},
new Object[]{2455443,"张速度","男","1569841525","156235ddf"},
new Object[]{2455443,"张仙","女","1569841525","156235ddf"},
new Object[]{2455443,"张速度","男","1569841525","156235ddf"},
new Object[]{2455443,"张速度","男","1569841525","156235ddf"},
};
final DefaultTableModel modelForm = new DefaultTableModel(meishiDate,meishititle) //不可编辑
{
public boolean isCellEditable(int row,int column)
{
return false;
}
};
datetable=new JTable(modelForm);
datetable.getTableHeader().setReorderingAllowed(false); //关闭拖放  
datetable.setSelectionBackground(new Color(51,123,176));
datetable.setSelectionForeground(Color.white);
datetable.setGridColor(Color.black);
datetable.setPreferredScrollableViewportSize(new Dimension(755, 447)); //设置表格大小
datetable.getTableHeader().setResizingAllowed(true);
datetable.setRowHeight(18); //每行表格的高度
datetable.setGridColor(new Color(78,50,92));
datetable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //单选
final JButton add = new JButton("添加(T)");
add.setMnemonic('T');
final JButton res = new JButton("修改(X)");
res.setMnemonic('X');
final JButton modify = new JButton("删除(R)");
modify.setMnemonic('R');
final JButton res1= new JButton("修改测试");
// add.setMargin(new Insets(0, 0, 0, 0));  

ActionListener action1=new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(e.getSource()==add){
new AddDialog().init();
}
else if(e.getSource()==res){
String[] Cells=new String[5];
for(int i=0;i<Cells.length;i++){
Cells[i]="新增"+modelForm.getRowCount()+" "+i;
}
modelForm.addRow(Cells);
}
else if(e.getSource()==res1){
// datetable.addMouseListener(new MouseAdapter(){ //鼠标事件
// public void mouseClicked(MouseEvent e){
// int selectedRow = datetable.getSelectedRow(); //获得选中行索引
// Object a = modelForm.getValueAt(selectedRow, 0);
// Object b = modelForm.getValueAt(selectedRow, 1);
// Object c = modelForm.getValueAt(selectedRow, 2);
// Object d = modelForm.getValueAt(selectedRow, 3);
// Object f = modelForm.getValueAt(selectedRow, 4);
//  
// jaccount.setTitle(a.toString()); //给文本框赋值
// jname.setTitle(b.toString());
// jsex.setTitle(c.toString());
// jphone.setTitle(d.toString());
// jpassword.setTitle(f.toString());
//  
// }
//  
// });
new AddDialog().init();
}
else if(e.getSource()==modify){  
int[] selected=datetable.getSelectedRows();
int i = datetable.getSelectedRow();
if(i==-1){
JOptionPane.showMessageDialog(null, "请选择条目!");
}else{
for(int j=selected.length-1;j>=0;j--){
modelForm.removeRow(selected[j]);
}
}
}
}
};
add.addActionListener(action1);
res.addActionListener(action1);
modify.addActionListener(action1);
res1.addActionListener(action1);

jp3. add(new JScrollPane(datetable));
jp3.add(add, BorderLayout.EAST);
jp3.add(res, BorderLayout.EAST);
jp3.add(modify, BorderLayout.EAST);
jp3.add(res1, BorderLayout.EAST);
jp.add(jp1,"1");
jp.add(jp2,"2");
jp.add(jp3,"3");
add(jp);
ActionListener action=new ActionListener(){
public void actionPerformed(ActionEvent e ){
if(e.getSource()==open){
card.show(jp,"1");
}
else if(e.getSource()==on){
card.show(jp,"2");
}
else if(e.getSource()==exit){
System.exit(0);
}
else if(e.getSource()==biaoge){
card.show(jp, "3");
}
}
};

open.addActionListener(action);
on.addActionListener(action);
biaoge.addActionListener(action);
exit.addActionListener(action);
open.setAccelerator(KeyStroke.getKeyStroke('O',InputEvent.CTRL_MASK));
on.setAccelerator(KeyStroke.getKeyStroke('S',InputEvent.CTRL_MASK));
biaoge.setAccelerator(KeyStroke.getKeyStroke('B',InputEvent.CTRL_MASK));
exit.setAccelerator(KeyStroke.getKeyStroke("F4"));
jmu.add(open);
jmu.add(on);
jmu.addSeparator();
jmu.add(biaoge);
jmu.addSeparator();
jmu.add(exit);
jmb.add(jmu);//贴
setResizable(false);
setVisible(true);
Image image=new ImageIcon("2.png").getImage();
setIconImage(image);
setTitle("CARDLAYOUt布局测试");
setJMenuBar(jmb);
setSize(780,560);
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
}
public static void main(String args[]){

new CardLyouta().init();
}
public void addRow(String[] arr) {
// TODO Auto-generated method stub

}
public void addRow(String string) {
// TODO Auto-generated method stub

}
public String getRowCount() {
// TODO Auto-generated method stub
return null;
}  
}






1 个回复

倒序浏览
自己先顶下
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马