z3sm2012是什么意思思?

java 在图片上写文字 - 小杨学Java之z3sm2012 - ITeye技术网站
博客分类:
功能:直接在一张已有的图片上写字,可指定文字颜色。
如果背景图片是空,生成一张白图片,根据文本信息,来决定图片的长度和宽度。 import java.awt.Cimport java.awt.Fimport java.awt.Gimport java.awt.image.BufferedIimport java.io.BufferedRimport java.io.Fimport java.io.FileNotFoundEimport java.io.FileRimport java.io.IOEimport java.util.ArrayLimport java.util.Aimport java.util.Iimport java.util.Limport javax.imageio.ImageIO;public class Draw {
private static Font mFont = new Font("宋体",Font.PLAIN,20);
public static void main(String[] args) {
File f1 = new File("C:\\Documents and Settings\\xugang\\桌面\\t.txt");
File f2 = new File("C:\\Documents and Settings\\xugang\\桌面\\testPictrue.JPEG");
File f3 = new File("C:\\Documents and Settings\\xugang\\桌面\\1.jpg");
draw2(f1,f2,f3,true);
//直接在一张已有的图片上写字,可指定文字颜色。如果背景图片参数为空或者"",则写张白图
public static void draw2( File content , File outPictrue , File background , boolean b ){
FileReader f =
f = new FileReader(content);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
BufferedReader br = new BufferedReader(f);
String line = "";
int lineNum = 0 ;
//一共有多少行
List&String& list = new ArrayList&String&();
while( (line = br.readLine()) != null){
System.out.println(line);
list.add(line);
} catch (IOException e1) {
e1.printStackTrace();
int[] iArray = new int[list.size()];
int length = list.size();
for(int k = 0 ; k & k++){
iArray[k] = format1(list.get(k));
Arrays.sort(iArray);
int lineLength = iArray[length-1];
System.out.println("文本中最长的一行的长度是:"+lineLength);
System.out.println("一共的行数是:"+lineNum);
BufferedImage image =
if( background.equals("") || background == null){
double h = 256/16;
double w = 85/10;
int width=(int) (w*lineLength)+ 40 , height=(int) (h*lineNum);
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
image = ImageIO.read(background);
} catch (IOException e1) {
e1.printStackTrace();
Graphics g = image.getGraphics();//
g.setColor(getRandColor(200,250));//
g.fillRect(1, 1, width-1, height-1);
if( b == false){
g.setColor(new Color(102,102,102));
//设字体为黑色,否则就是白色
g.drawRect(0, 0, width-1, height-1);
g.setFont(mFont);
int k = 0;
Iterator&String& it = list.iterator();
while(it.hasNext()){
g.drawString(it.next(), 30, 15 + 20*k);
ImageIO.write(image, "JPEG", outPictrue);
} catch (IOException e) {
e.printStackTrace();
//返回占位符的长度。
public static int format1( String s){
int length = 0 ;
for(int t = 0; t & s.length() ; t++){
if( s.charAt(t)& 255){
length = length + 2;
length = length + 1 ;
System.out.println(length);
//生成一张白图片,根据文本信息,来决定图片的长度和宽度。
//缺点:字体不同,字体样式不同,都会影响整个图片。
public static void draw1(){
FileReader f =
f = new FileReader("C:\\Documents and Settings\\xugang\\桌面\\t.txt");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
BufferedReader br = new BufferedReader(f);
String line = "";
int lineNum = 0 ;
//一共有多少行
List&String& list = new ArrayList&String&();
while( (line = br.readLine()) != null){
System.out.println(line);
list.add(line);
} catch (IOException e1) {
e1.printStackTrace();
int[] iArray = new int[list.size()];
int length = list.size();
for(int k = 0 ; k & k++){
iArray[k] = format1(list.get(k));
Arrays.sort(iArray);
int lineLength = iArray[length-1];
System.out.println("文本中最长的一行的长度是:"+lineLength);
System.out.println("一共的行数是:"+lineNum);
double h = 256/16;
double w = 85/10;
int width=(int) (w*lineLength)+ 40 , height=(int) (h*lineNum);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();//
g.setColor(getRandColor(200,250));
g.fillRect(1, 1, width-1, height-1);
g.setColor(new Color(102,102,102));
g.drawRect(0, 0, width-1, height-1);
g.setFont(mFont);
int k = 0;
Iterator&String& it = list.iterator();
while(it.hasNext()){
g.drawString(it.next(), 30, 15+15*k);
ImageIO.write(image, "JPEG", new File("C:\\Documents and Settings\\xugang\\桌面\\testPictrue.JPEG"));
} catch (IOException e) {
e.printStackTrace();
小杨学JAVA
浏览: 457859 次
来自: 上海
POI处理的格式单一,无法导出格式比较复杂的表格。POI不能使 ...
jqgrid 按回车键默认提交数据,怎么做才能时回车不提交数据 ...
nice 很多情况都是因为引入文件导入
bootstrap demo实例教程源代码下载:http:// ...
不错,谢谢!用法 — 定义Tab标签样式 - 小杨学Java之z3sm2012 - ITeye技术网站
博客分类:
转载自:/wader2011/archive//2209668.html
在上一篇文章“TabHost用法”中我们介绍了通过TabHost实现标签页效果。但是在实际项目中我们可能更希望定义自己的Tab标签样式使界面效果更佳。既然不能改变系统的Tab样式,那么我们可以选择隐藏系统的东西,使用自己定义的东西(这种方式很好用,以后会详细介绍)。反编译新浪微博的项目后会发现,他们在布局中隐藏了TabWidget即Tab标签而使用一组RadioButton来代替。既然是自己定义的,那肯定是可以自己决定显示样式了,那我们的问题也就解决了。这里我使用的是“TabHost用法—两种实现方式”一文种提到的第二种实现方式,继承Activity来使用TabHost的。先把代码贴上来(红色字体部分为修改或添加的代码)。
TabHostActivity.java
public class TabHostActivity extends Activity implements
OnCheckedChangeListener {
private TabHost tabHost;
private Intent certificateIntent;
private Intent feeIntent;
private Intent scoreIntent;
private Intent studyIntent;
private Intent moreIntent;
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
// tabHost = getTabHost();
tabHost = (TabHost) findViewById(R.id.my_tabhost);
LocalActivityManager groupActivity =
new LocalActivityManager(this,false);
groupActivity.dispatchCreate(savedInstanceState);
tabHost.setup(groupActivity);
initIntent();
addSpec();
((RadioGroup) findViewById(R.id.tab_radiogroup))
.setOnCheckedChangeListener(this);
* 初始化各个tab标签对应的intent
privatevoid initIntent() {
studyIntent = new Intent(this, StudyActivity.class);
scoreIntent = new Intent(this, ScoreActivity.class);
feeIntent = new Intent(this, FeeActivity.class);
certificateIntent = new Intent(this, CertificateActivity.class);
moreIntent = new Intent(this, MoreActivity.class);
* 为tabHost添加各个标签项
privatevoid addSpec() {
tabHost.addTab(this.buildTagSpec("tab_study", R.string.study_progress,
R.drawable.account01, studyIntent));
tabHost.addTab(this.buildTagSpec("tab_score", R.string.test_score,
R.drawable.account02, scoreIntent));
tabHost.addTab(this.buildTagSpec("tab_fee", R.string.fee_pay,
R.drawable.account03, feeIntent));
tabHost.addTab(this.buildTagSpec("tab_certificate",
R.string.certificate_grant, R.drawable.account04,
certificateIntent));
tabHost.addTab(this.buildTagSpec("tab_more", R.string.more,
R.drawable.account05, moreIntent));
* 自定义创建标签项的方法
* @param tagName 标签标识
* @param tagLable 标签文字
* @param icon 标签图标
* @param content 标签对应的内容
private TabHost.TabSpec buildTagSpec(String tagName, int tagLable,
int icon, Intent content) {
returntabHost
.newTabSpec(tagName)
.setIndicator(getResources().getString(tagLable),
getResources().getDrawable(icon)).setContent(content);
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_button_study:
tabHost.setCurrentTabByTag("tab_study");
case R.id.radio_button_score:
tabHost.setCurrentTabByTag("tab_score");
case R.id.radio_button_certificate:
tabHost.setCurrentTabByTag("tab_certificate");
case R.id.radio_button_fee:
tabHost.setCurrentTabByTag("tab_fee");
case R.id.radio_button_more:
tabHost.setCurrentTabByTag("tab_more");
&?xml version="1.0" encoding="UTF-8"?&
&TabHost android:id="@+id/my_tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="/apk/res/android"&
&LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"&
&FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="0.0dip"
android:layout_weight="1.0" /&
&TabWidget android:id="@android:id/tabs" android:visibility="gone"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0.0" /&
&RadioGroup android:id="@+id/tab_radiogroup"
android:background="@drawable/tabs_bg" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center_vertical"
android:layout_gravity="bottom" android:orientation="horizontal"&
&RadioButton android:id="@+id/radio_button_study"
android:layout_marginTop="2.0dip" android:text="学习进度"
android:drawableTop="@drawable/account01" style="@style/tab_button_bottom"
android:checked="true" /&
&RadioButton android:id="@+id/radio_button_score"
android:layout_marginTop="2.0dip" android:text="考试成绩"
android:drawableTop="@drawable/account02" style="@style/tab_button_bottom" /&
&RadioButton android:id="@+id/radio_button_certificate"
android:layout_marginTop="2.0dip" android:text="证书发放"
android:drawableTop="@drawable/account03" style="@style/tab_button_bottom" /&
&RadioButton android:id="@+id/radio_button_fee"
android:layout_marginTop="2.0dip" android:text="费用缴纳"
android:drawableTop="@drawable/account04" style="@style/tab_button_bottom" /&
&RadioButton android:id="@+id/radio_button_more"
android:layout_marginTop="2.0dip" android:text="更多"
android:drawableTop="@drawable/account05" style="@style/tab_button_bottom" /&
&/RadioGroup&
&/LinearLayout&
&/TabHost&
styles.xml
&?xml version="1.0" encoding="utf-8"?&
&resources&
&!-- TabHost标签按钮样式 --&
&style name="tab_button_bottom"&
&item name="android:textSize"&12px&/item&
&item name="android:textColor"&#ffffffff&/item&
&item name="android:ellipsize"&marquee&/item&
&item name="android:gravity"&center_horizontal&/item&
&item name="android:background"&@drawable/tab_btn_bg&/item&
&item name="android:layout_marginTop"&2.0dip&/item&
&item name="android:button"&@null&/item&
&item name="android:paddingTop"&6dip&/item&
&item name="android:drawablePadding"&4dip&/item&
&item name="android:layout_width"&fill_parent&/item&
&item name="android:layout_height"&wrap_content&/item&
&item name="android:layout_weight"&1.0&/item&
&item name="android:singleLine"&true&/item&
&!-- 页面标题LinearLayout样式 --&
&style name="activity_title_background"&
&item name="android:background"&@drawable/title_background&/item&
&item name="android:layout_width"&fill_parent&/item&
&item name="android:layout_height"&wrap_content&/item&
&item name="android:layout_alignParentTop"&true&/item&
&item name="android:gravity"&center&/item&
&!-- 界面标题TextView样式 --&
&style name="activity_title_text"&
&item name="android:textSize"&14dip&/item&
&item name="android:textColor"&@drawable/white&/item&
&item name="android:layout_width"&wrap_content&/item&
&item name="android:layout_height"&wrap_content&/item&
&item name="android:gravity"&center&/item&
&/resources&
运行结果如下图所示
程序重要部分:
1.红色字体部分。
2.布局文件tab.xml,可以看到该布局文件中将TabWidget隐藏(android:visibility="gone")而以一个RadioGroup取而代之。
3.为RadioGroup设置OnCheckedChangeListener监听,通过onCheckedChanged方法对各个RadioButton点击事件的处理完成标签切换。
其实我当初考虑过为什么要用RadioButton而不用普通的Button。后来通过自己做项目,发现使用RadioGroup有以下优点:
1.另外就是布局上比较方便易懂,不用再去用LinearLayout等布局去包含Button。
2. 我们可以很方便的获得当前选中的标签,当然通过TabHost的tabHost.getCurrentTabTag()和getCurrentTab()也是可以的。
3.设置监听很方便,只需要为RadioGroup设置监听就行了,程序中对应的代码是
((RadioGroup) findViewById(R.id.tab_radiogroup))
.setOnCheckedChangeListener(this);
如果用Button的话我们需要为所有的Button一个一个去设置监听,相对来说比较麻烦。
4.或许最重要的一点是因为RadioButton本身就支持图片和文字的上下布局,只需指定图片和文字是什么就可以了而不需要我们自己去实现这种布局。
&RadioButton android:id="@+id/radio_button_more"
android:layout_marginTop="2.0dip"
android:text="更多"
android:drawableTop="@drawable/account05"
style="@style/tab_button_bottom" /&
当然如果如果RadioButton不能满足我们的项目需求,比如我们不需要图片又不想让文字靠底部显示,而是居中显示,这时我们就可以用其他组件代替RadioButton。其实我们可以通过修改或自定义等方式实现多种漂亮的效果,比如“人人网”手机客户端的个人主页中Tab标签是可以左右滑动的。
小杨学JAVA
浏览: 457861 次
来自: 上海
POI处理的格式单一,无法导出格式比较复杂的表格。POI不能使 ...
jqgrid 按回车键默认提交数据,怎么做才能时回车不提交数据 ...
nice 很多情况都是因为引入文件导入
bootstrap demo实例教程源代码下载:http:// ...
不错,谢谢!}

我要回帖

更多关于 hold是什么意思 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信