ContactManagementSystem总结
来源:互联网 发布:淘宝店铺运营模式 编辑:程序博客网 时间:2024/05/22 08:23
1.Java具有的观感名称以及类名
为JFrame设置观感的方法:
try { UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");//设置观感 SwingUtilities.updateComponentTreeUI(JFrame x);//刷新x以及其中的组件}catch(Exception e) { e.printStackTrace();}
2.一个组件(如JLabel)不能同时添加到两个容器中
3.JTabbedPane类:选项卡
public void setTabPlacement(int tabPlacement)//设置选项卡窗格的位置参数为:JTabbedPane.TOP JTabbedPane.BOTTOM JTabbedPane.LEFT JTabbedPane.RIGHT如果未设置默认为TOP
选项卡中默认文字是横向排列的,如果要让其纵向排列,则使用html表示,< br>表示换行
tab.add("<html><br>用<br><br>户<br><br>登<br><br>录<br></html>", load);//void add(String title,Component com);Adds a component with the specified tab title.
3 . 修改JFrame中组件的默认字体:使用UIManager
在构造函数中使用:put("相应组件名+.font",Font);UIManager.put("Label.font", font);UIManager.put("Button.font", font);UIManager.put("TextField.font", input);UIManager.put("PasswordField.font", input);UIManager.put("TabbedPane.font", font);改方法调用必须在组件初始化之前
4.JTextField/JPasswordField固定输入长度且只能输入特定字符:重写PlainDocument
/***使用方法:JTextField t = new JTextField();*t.setDocument(new JTextFieldLimit(15));*输入最大长度是15 */class JTextFieldLimit extends PlainDocument{//限制输入长度和字符 private Set<Character> set; private int limit; public JTextFieldLimit(int limit,Character[] a) {//a[]为想输入的字符数组 super(); this.limit = limit; this.set = new HashSet<>(Arrays.asList(a)); } public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException{ if(str == null) { return; } for(int i = 0;i < str.length();i++) { if((getLength()+str.length()) > limit || !set.contains(str.charAt(i))) return; super.insertString(offset, str, attr); } } }
5.set/array/list的相互转换
Integer[] a = {1,2,4,3};List<Integer> list = new ArrayList<>();list = Arrays.asList(a);a = list.toArray(new Integer[list.size()]);Set<Integer> set = new HashSet<>(list)//HashSet(Collection<? extends E> c)Set<Integer> set1 = new HashSet<>(Arrays.asList(a));list.addAll(set); //addAll(Colletion<?> c)
6.JPasswordField获取内容
JPasswordField f = new JPasswordField();String passWord = new String(f.getPassword());//char[] getPassword();//String(char[]);
7.System.getProperty(“user.dir”)返回工程的绝对路径
8.创建文件夹:
File file = new File(System.getProperty("user.dir")+"\\文件");if(!file.exists() && !file.isDirectory()) { file.mkdir();//创建“文件”文件夹}
创建该文件夹下的文件(必须在文件夹创建之后才能创建)
File file = new File(System.getProperty("user.dir")+"\\文件"+"\\user.txt");if(!file.exists()) file.createNewFile();//创建文件
9.写入文件和读取文件
写入文件:
File file = new File(System.getProperty("user.dir")+"\\文件"+"\\user.txt");FileWriter fw = new FileWriter(file);BufferedWriter bw = new BufferedWriter(fw);bw.write(name);bw.write(" ");bw.write(password);bw.write("\r\n");bw.flush();//刷新流bw.close();
读取文件:
File file = new File(System.getProperty("user.dir")+"\\文件"+"\\user.txt");FileReader fr = null;try { fr = new FileReader(file);}catch(IOException e) { System.out.println("读取文件错误");}BufferedReader br = new BufferedReader(fr);count = 0;String s = "";try { while((s = br.readLine()) != null) { Scanner in = new Scanner(s); name[count] = in.next(); name[count] = in.next(); count++; }}catch(IOException e) { system.out.println("文件写入错误");}try { br.close();}catch(IOException e) { System.out.println("文件关闭错误");}
10.修改图片大小
Image Image.getScaledInstance(int width,int height,int hints)//将图像缩放成相对应的比例width - the width to which to scale the image. height - the height to which to scale the image. hints - flags to indicate the type of algorithm to use for image resampling.SCALE_DEFAULT, SCALE_FAST, SCALE_SMOOTH, SCALE_REPLICATE, SCALE_AREA_AVERAGING
阅读全文
0 0
- ContactManagementSystem总结
- 总结
- 总结
- 总结
- 总结
- 总结!
- 总结
- 总结.
- 总结。
- 总结
- 总结
- 总结
- 总结
- 总结
- 总结
- 总结
- 总结
- 总结
- 支付宝手机网站支付接入详细教程
- 解决java compiler level does not match the version of the installed java project facet
- 手摸手,带你用vue撸后台 系列二(登录权限篇)
- iis短文件名漏洞处理方法
- linux查看存储盘
- ContactManagementSystem总结
- JavaScript获取video的暂停、播放事件,并切换清晰度
- 美团点评完成40亿美元融资,腾讯领投
- 给马云、马化腾订制旅行,这家公司想做旅游行业的“得到”
- win7 安装sql server2000
- iOS开发内购详细版本说明
- Elasticsearch中 X-Pack破解试用
- 虚拟机压力测试延迟高的可能原因及 ILPIP 配置 / 查询脚本
- C语言实验——计算表达式