java之swing表格完成辦法。本站提示廣大學習愛好者:(java之swing表格完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是java之swing表格完成辦法正文
本文實例講述了java之swing下拉菜單完成辦法。分享給年夜家供年夜家參考。詳細以下:
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class test extends JApplet implements ItemListener{ JLabel jtf; ImageIcon a1, a2, a3; public void init(){ Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); JComboBox jc = new JComboBox(); jc.addItem("6"); jc.addItem("7"); jc.addItem("8"); jc.addItemListener(this); contentPane.add(jc); jtf = new JLabel(new ImageIcon("D:/data/Images/6.gif")); contentPane.add(jtf); } public void itemStateChanged(ItemEvent ie){ String s = (String)ie.getItem(); jtf.setIcon(new ImageIcon("D:/data/Images/"+s+".gif")); } }
願望本文所述對年夜家的java法式設計有所贊助。
trics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.heightPixels; }獲得屏幕密度:
/** * 獲得屏幕密度 * @param context * @return * by Hankkin at:2015-10-07 21:16:29 */ public static float getScreenDensity(Context context) { return context.getResources().getDisplayMetrics().density; }
dip轉px:
/** * dip轉px像素 * @param context * @param px * @return * by Hankkin at:2015-10-07 21:16:43 */ public static int dip2px(Context context, float px) { final float scale = getScreenDensity(context); return (int) (px * scale + 0.5); }
獲得狀況欄高度:
/** * 取得狀況欄的高度 * @param context * @return * by Hankkin at:2015-10-07 21:16:43 */ public static int getStatusHeight(Context context) { int statusHeight = -1; try { Class<?> clazz = Class.forName("com.android.internal.R$dimen"); Object object = clazz.newInstance(); int height = Integer.parseInt(clazz.getField("status_bar_height") .get(object).toString()); statusHeight = context.getResources().getDimensionPixelSize(height); } catch (Exception e) { e.printStackTrace(); } return statusHeight; }
獲得屏幕以後截圖:
/** * 獲得以後屏幕截圖,包括狀況欄 * @param activity * @return * by Hankkin at:2015-10-07 21:16:43 */ public static Bitmap snapShotWithStatusBar(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bmp = view.getDrawingCache(); int width = getScreenWidth(activity); int height = getScreenHeight(activity); Bitmap bp = null; bp = Bitmap.createBitmap(bmp, 0, 0, width, height); view.destroyDrawingCache(); return bp; } /** * 獲得以後屏幕截圖,不包括狀況欄 * @param activity * @return * by Hankkin at:2015-10-07 21:16:43 */ public static Bitmap snapShotWithoutStatusBar(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true); view.buildDrawingCache(); Bitmap bmp = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = getScreenWidth(activity); int height = getScreenHeight(activity); Bitmap bp = null; bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return bp; }
以上所述是本文給年夜家引見的Android獲得經常使用幫助辦法(獲得屏幕高度、寬度、密度、告訴欄高度、截圖),願望對年夜家也是贊助,更多信息登錄網站懂得更多信息。