1 flaot 取小数点
/**
* 把传入的双精度变量或单精度变量转化为两位小数的形式输出
* */
public float getInvertDataDouble(float para)
{
DecimalFormat decimalFormat=new DecimalFormat("0.00");
String s=decimalFormat.format(para);
float a=Float.parseFloat(s);
return a;
}
2对话框显示
SwingUtilities.getAncestorOfClass(Frame.class,this)
处理网页对话框显示在网页底下
3字符处理
StringTokenizer st = new StringTokenizer(CurveLabel, "%");
String[] value = new String[4];
int l = 0;
while (st.hasMoreElements()) {
value[l] = (String) st.nextElement();
l = l + 1;
}
String shujuleixing = value[0];
String ycxm = value[1];
String riqi = value[2];
4对话框
String message = "已有DSM修正预测数据!";
int result = JOptionPane.showOptionDialog(SwingUtilities.getAncestorOfClass(Frame.class,this), message, title,
optionType, messageType, null, options, options[1]);
dialog
5布局
setbounds 只有在布局为null的时候有用
setPreferredSize在布局的时候有用 但是布局器可能自动设置其大小
可以设置 setMaximumSize 最大大小
6servlet和程序用的不是一个classes12包
(1)servlet调用的class12和程序调用的class12不一样 在dafaultroot里
(2)ldfserver问题主要是 oracle8i 与oracle9i客户端不兼容 将9i的dll拷到bin目录下即可
7
if (e.getValueIsAdjusting()) { //list不处理
return;
}
8 setVisible(true/false) 使组件是否可见
加完以后要重新布一下局.revalidate();
9JCheckBox 可以用addActionListener() 然后在actionperformed里 查看是否isSelected
10 JTable 必须加滚动才出列名
11对话框
String title="Message Dialog";
String message="";
int type=JOptionPane.PLAIN_MESSAGE;
if (cmd.equals("Show Error Icon")){
type=JOptionPane.ERROR_MESSAGE;
message="Error Message";
}else if (cmd.equals("Show Information Icon")){
type=JOptionPane.INFORMATION_MESSAGE;
message="information Message";
}else if (cmd.equals("Show Waring Icon")){
type=JOptionPane.WARNING_MESSAGE;
message="Waring Message";
}else if (cmd.equals("Show Question Icon")){
type=JOptionPane.QUESTION_MESSAGE;
message="Question Message";
}else if (cmd.equals("Show Plain Icon")){
type=JOptionPane.PLAIN_MESSAGE;
message="Plain Message";
}else if (cmd.equals("Show User Define Icon")){
type=JOptionPane.PLAIN_MESSAGE;
JOptionPane.showMessageDialog(f,message,title,type,new ImageIcon("..\\icons\\glass.jpg"));
return ;
}
JOptionPane.showMessageDialog(f,message,title,type);
12
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);//自动设置大小 在用滚动条的时候管用
table.setColumnSelectionAllowed(true);//设置选择模式 行或列
13 list触发两次事件处理
if (e.getValueIsAdjusting()) { //list不处理
return;
}
14 和list里的内容进行比较
DefaultListModel getdm=(DefaultListModel) sflist.getModel();
if(getdm.contains(name))
{
type = JOptionPane.ERROR_MESSAGE;
message = "组合算法名称已经存在!";
JOptionPane.showMessageDialog(f, message, title, type);
return;
}
15进度条
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ProgressBartr implements ActionListener {
/**
* @param args
*/
JProgressBar pb = new JProgressBar();
public static void main(String[] args) {
// TODO 自动生成方法存根
new ProgressBartr();
}
public ProgressBartr() {
JFrame f = new JFrame();
Container con=f.getContentPane();
con.setLayout(new FlowLayout());
JButton jb=new JButton("button");
jb.addActionListener(this);
//pb.setIndeterminate(true);
pb.setValue(0);
pb.setMaximum(100);
pb.setStringPainted(true);
pb.setPreferredSize(new Dimension(250,25));
pb.setMaximumSize(new Dimension(250,250));
con.add(jb);
con.add(pb);
f.setBounds(new Rectangle(300, 300, 300, 300));
f.show();
}
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成方法存根
Thread runner = new Thread() {
public void run() {
pb.setStringPainted(true);
for (int i = 0; i < 100; i++) {
pb.setValue(i);
try {
sleep(100);
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
pb.setValue(0);
pb.setStringPainted(false);
}
};
runner.start();
}
}
16 数据库操作 日期转换????????
select * from table where MARKETDATE(date)=to_date('2006/03/19','yyyy/mm/dd')
告诉 日期格式 自动转换
17 applet ---->jsp
public void toNext() {
try{
this.getAppletContext().showDocument(new URL(this.getCodeBase()+"pmCtrDecFiv_up.jsp?year="+year+"&unit_id="+unit_id),"_blank");
}catch(Exception ex){}
}
18 tree 线显示为红色
UIManager.put( "Tree.hash", new ColorUIResource(Color.red) );
19 JButton颜色切换
if(obj==jb)
{
jb.setBackground(Color.ORANGE);
jb1.setBackground(null);
}
if(obj==jb1)
{
jb1.setBackground(Color.ORANGE);
jb.setBackground(null);
}
20 ftp处理
try {
FTPClient fc = new FTPClient("10.34.20.78");
fc.login("ftp", "ftp");
fc.setType(FTPTransferType.ASCII);
fc.put("e:/java/ftp/ftp.TXT", "/abc/b.txt");//第一个参数为源 第二个为目的
fc.quit();
} catch (Exception e) {}
21StringTokenizer
StringTokenizer st = new StringTokenizer("sss%ddd%eee%ttt%", "%");
Vector val = new Vector();
int l = 0;
System.out.print(st.countTokens() );
int num=st.countTokens() ;
while (st.hasMoreElements()) {
val.addElement(st.nextElement());
l = l + 1;
}
22得到服务器IP
this.getCodeBase().toString()
23 Runtime.getRuntime().exec("ping 172.20.42.71");
执行命令
String URL="\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"
http://www.china.com
";
Process pp=Runtime.getRuntime().exec(URL);
24 将字符串转换为Date
import java.text.SimpleDateFormat;
String t="2006-05-09";
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
Date d=sdf1.parase(t);
25 setOpaque(false)设置透明
26 OptionPane设置背景颜色
Color oldColor1=UIManager.getColor("OptionPane.background"); Color oldColor2=UIManager.getColor("Panel.background"); String okButtonText=UIManager.getString("OptionPane.okButtonText"); String okButtonMnemonic=UIManager.getString("OptionPane.okButtonMnemonic");
UIManager.put("OptionPane.background",Color.cyan); UIManager.put("Panel.background",Color.yellow); UIManager.put("OptionPane.okButtonText","HaHaHa!!!"); UIManager.put("OptionPane.okButtonMnemonic",""+((int)'H')); JOptionPane.showMessageDialog(this,"<HTML><B>SUNKING</B><BR><Font Color=green>" +"SUNKING </font><BR><I>SUNKING</I></html>");
UIManager.put("OptionPane.background",oldColor1); UIManager.put("Panel.background",oldColor2); UIManager.put("OptionPane.okButtonText",okButtonText); UIManager.put("OptionPane.okButtonMnemonic",okButtonMnemonic);
27使用图片 ../指上一层
URL url=chat.MainFrame.class.getResource("../images/mm.jpg") ;