GVKun编程网logo

为什么JFrame重新定义它从接口“ WindowConstants”继承的“ EXIT_ON_CLOSE”?(为什么java的jframe一直显示错误)

7

针对为什么JFrame重新定义它从接口“WindowConstants”继承的“EXIT_ON_CLOSE”?和为什么java的jframe一直显示错误这两个问题,本篇文章进行了详细的解答,同时本文还

针对为什么JFrame重新定义它从接口“ WindowConstants”继承的“ EXIT_ON_CLOSE”?为什么java的jframe一直显示错误这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展activityCloseExitAnimation在windowIsTranslucent设置为true时不起作用、android – 将AutoCompleteTextView过滤器从“startsWith”更改为“Contains”?、cocoa – Core Text的CTFramesetterSuggestFrameSizeWithConstraints()每次都返回不正确的大小、Cocos2d-x之onEnter()、onEnterTransitionDidFinish()、onExit()、onExitTransitionDidStart()等相关知识,希望可以帮助到你。

本文目录一览:

为什么JFrame重新定义它从接口“ WindowConstants”继承的“ EXIT_ON_CLOSE”?(为什么java的jframe一直显示错误)

为什么JFrame重新定义它从接口“ WindowConstants”继承的“ EXIT_ON_CLOSE”?(为什么java的jframe一直显示错误)

WindowConstants 定义如下:

public interface WindowConstants{    public static final int DO_NOTHING_ON_CLOSE = 0;    public static final int HIDE_ON_CLOSE = 1;    public static final int DISPOSE_ON_CLOSE = 2;    public static final int EXIT_ON_CLOSE = 3;}

JFrame 定义如下:

public class JFrame  extends Frame implements WindowConstants,                                              Accessible,                                              RootPaneContainer,                              TransferHandler.HasGetTransferHandler{    /**     * The exit application default window close operation. If a window     * has this set as the close operation and is closed in an applet,     * a <code>SecurityException</code> may be thrown.     * It is recommended you only use this in an application.     * <p>     * @since 1.3     */    public static final int EXIT_ON_CLOSE = 3;

为什么EXIT_ON_CLOSE要重新定义?并且由于它finalWindowConstants界面中,如何重新定义它?

答案1

小编典典

在Java
1.3中,添加了所有功能之后,EXIT_ON_CLOSE它仅JFrame与无关,而与的其他实现无关WindowConstants。这样-这是

存在于WindowConstants和被定义JFrameXXX_ON_CLOSE界面中还有其他3个选项。(英语Javadoc不再在线,尽管仍然可以下载,所以这里没有参考。如果搜索“
WindowConstants Java 1.3”,您将获得日语版的Javadoc-但由于页面结构相同,因此您仍然可以看到点)

后来(1.4)移至WindowConstants,但是JFrame由于兼容性问题,该字段未被删除。

activityCloseExitAnimation在windowIsTranslucent设置为true时不起作用

activityCloseExitAnimation在windowIsTranslucent设置为true时不起作用

如何解决activityCloseExitAnimation在windowIsTranslucent设置为true时不起作用?

我有一个半透明的活动,我正在尝试更改退出动画,但是在windowIsTranslucent设置为true的情况下似乎不起作用,例如:

<style name="Animation">
    <item name="android:activityOpenEnteranimation">@android:anim/fade_in</item>
    <item name="android:activityCloseExitAnimation">@android:anim/fade_out</item>
</style>
<style name="TranslucentTheme" parent="android:Theme.Material.Light.NoActionBar">
    <item name="android:colorBackground">#99000000</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@style/Animation</item>
</style>

如果我将android:windowIsTranslucent更改为false,它将正常工作,这似乎只影响退出动画,而enter动画正常。我做错了吗?还有另一种方法吗?谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

android – 将AutoCompleteTextView过滤器从“startsWith”更改为“Contains”?

android – 将AutoCompleteTextView过滤器从“startsWith”更改为“Contains”?

我想更改AutoCompleteTextView中的默认过滤.默认筛选查找以给定标记开始的所有字符串.我的项目要求过滤应该找到包含给定标记的所有字符串.

可能吗?

解决方法

我找到了一个解决方案,感谢Google和搜索两天.正如@ torque203建议的那样,我已经实现了自己的自定义适配器.首先在适配器中为自定义Item定义一个新的 XML文件:

autocomplete_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        android:paddingTop="16dp"
        android:paddingBottom="16dp"
        android:id="@+id/lbl_name" />
</RelativeLayout>

为您的名称创建新类:

名称

public class Names {
    public String name;
}

NamesAdapter

public class NamesAdapter extends ArrayAdapter<Names> {

    Context context;
    int resource,textViewResourceId;
    List<Names> items,tempItems,suggestions;

    public NamesAdapter(Context context,int resource,int textViewResourceId,List<Names> items) {
        super(context,resource,textViewResourceId,items);
        this.context = context;
        this.resource = resource;
        this.textViewResourceId = textViewResourceId;
        this.items = items;
        tempItems = new ArrayList<Names>(items); // this makes the difference.
        suggestions = new ArrayList<Names>();
    }

    @Override
    public View getView(int position,View convertView,ViewGroup parent) {
        View view = convertView;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.autocomplete_item,parent,false);
        }
        Names names = items.get(position);
        if (names != null) {
            TextView lblName = (TextView) view.findViewById(R.id.lbl_name);
            if (lblName != null)
                lblName.setText(names.name);
        }
        return view;
    }

    @Override
    public Filter getFilter() {
        return nameFilter;
    }

    /**
     * Custom Filter implementation for custom suggestions we provide.
     */
    Filter nameFilter = new Filter() {
        @Override
        public CharSequence convertResultToString(Object resultValue) {
            String str = ((Names) resultValue).name;
            return str;
        }

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            if (constraint != null) {
                suggestions.clear();
                for (Names names : tempItems) {
                    if (names.name.toLowerCase().contains(constraint.toString().toLowerCase())) {
                        suggestions.add(names);
                    }
                }
                FilterResults filterResults = new FilterResults();
                filterResults.values = suggestions;
                filterResults.count = suggestions.size();
                return filterResults;
            } else {
                return new FilterResults();
            }
        }

        @Override
        protected void publishResults(CharSequence constraint,FilterResults results) {
            List<Names> filterList = (ArrayList<Names>) results.values;
            if (results != null && results.count > 0) {
                clear();
                for (Names names : filterList) {
                    add(names);
                    notifyDataSetChanged();
                }
            }
        }
    };
}

SearchActivity(或您的主要活动)

....
   List<Names> namesList =  //your names list;
   NamesAdapter namesAdapter = new NamesAdapter(
                    SearchActivity.this,R.layout.activity_search,R.id.lbl_name,namesList
            );
            //set adapter into listStudent
            autoCompleteTextView.setAdapter(namesAdapter);
            autoCompleteTextView.showDropDown();
...

cocoa – Core Text的CTFramesetterSuggestFrameSizeWithConstraints()每次都返回不正确的大小

cocoa – Core Text的CTFramesetterSuggestFrameSizeWithConstraints()每次都返回不正确的大小

根据文档,CTFramesetterSuggestFrameSizeWithConstraints()“确定字符串范围所需的帧大小”.

不幸的是,这个函数返回的大小永远不准确.这是我在做的事情:

NSAttributedString *string = [[[NSAttributedString alloc] initWithString:@"lorem ipsum" attributes:nil] autorelease];
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef) string);
    CGSize textSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter,CFRangeMake(0,0),NULL,CGSizeMake(rect.size.width,CGFLOAT_MAX),NULL);

返回的大小始终具有正确的宽度计算,但高度始终略短于预期.

这是使用此方法的正确方法吗?

有没有其他方法来布局核心文本?

似乎我不是唯一遇到此方法问题的人.见https://devforums.apple.com/message/181450.

编辑:
我使用sizeWithFont:使用Quartz测量相同的字符串,为属性字符串和Quartz提供相同的字体.以下是我收到的测量数据:

Core Text: 133.569336 x 16.592285

Quartz: 135.000000 x 31.000000

解决方法

试试这..似乎工作:
+(CGFloat)heightForAttributedString:(NSAttributedString *)attrString forWidth:(CGFloat)inWidth
{
    CGFloat H = 0;

    // Create the framesetter with the attributed string.
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString( (CFMutableAttributedStringRef) attrString); 

    CGRect Box = CGRectMake(0,inWidth,CGFLOAT_MAX);

    CFIndex startIndex = 0;

    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path,Box);

    // Create a frame for this column and draw it.
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter,CFRangeMake(startIndex,path,NULL);

    // Start the next frame at the first character not visible in this frame.
    //CFRange frameRange = CTFrameGetVisibleStringRange(frame);
    //startIndex += frameRange.length;

    CFArrayRef lineArray = CTFrameGetLines(frame);
    CFIndex j = 0,lineCount = CFArrayGetCount(lineArray);
    CGFloat h,ascent,descent,leading;

    for (j=0; j < lineCount; j++)
    {
        CTLineRef currentLine = (CTLineRef)CFArrayGetValueAtIndex(lineArray,j);
        CTLineGetTypographicBounds(currentLine,&ascent,&descent,&leading);
        h = ascent + descent + leading;
        NSLog(@"%f",h);
        H+=h;
    }

    CFRelease(frame);
    CFRelease(path);
    CFRelease(framesetter);


    return H;
}

Cocos2d-x之onEnter()、onEnterTransitionDidFinish()、onExit()、onExitTransitionDidStart()

Cocos2d-x之onEnter()、onEnterTransitionDidFinish()、onExit()、onExitTransitionDidStart()

在多个场景切换时候,场景的生命周期会更加复杂。这一节我们介绍一下场景切换生命周期。

多个场景切换时候分为几种情况:

情况1,使用pushScene函数从实现HelloWorld场景进入Setting场景。

情况2,使用replaceScene函数实现从HelloWorld场景进入Setting场景。

情况3,使用popScene函数从实现Setting场景回到HelloWorld场景。

我们参考HelloWorld重写Setting层的中几个生命周期函数,代码如下:

boolSetting::init()

{

if(!Layer::init())

{

returnfalse;

}

log("Settinginit");

......

returntrue;

}

voidSetting::onEnter()

{

Layer::onEnter();

log("SettingonEnter");

}

voidSetting::onEnterTransitionDidFinish()

{

Layer::onEnterTransitionDidFinish();

log("SettingonEnterTransitionDidFinish");

}

voidSetting::onExit()

{

Layer::onExit();

log("SettingonExit");

}

voidSetting::onExitTransitionDidStart()

{

Layer::onExitTransitionDidStart();

log("SettingonExitTransitionDidStart");

}

voidSetting::cleanup()

{

Layer::cleanup();

log("Settingcleanup");

}

情况1时候,它的调用顺序如下图所示。


情况2时候,它的调用顺序如下图所示,从图中可见与上面不同是多出HelloWorld中cleanup函数,这也说明replaceScene函数会释放场景对象。


情况3时候,它的调用顺序如下图所示,从图中可见popScene函数时候调用Setting中cleanup函数,这说明popScene函数会释放Setting场景对象,当回到HelloWorld场景时候并不会调用init()函数,而是调用onEnter函数。

今天关于为什么JFrame重新定义它从接口“ WindowConstants”继承的“ EXIT_ON_CLOSE”?为什么java的jframe一直显示错误的介绍到此结束,谢谢您的阅读,有关activityCloseExitAnimation在windowIsTranslucent设置为true时不起作用、android – 将AutoCompleteTextView过滤器从“startsWith”更改为“Contains”?、cocoa – Core Text的CTFramesetterSuggestFrameSizeWithConstraints()每次都返回不正确的大小、Cocos2d-x之onEnter()、onEnterTransitionDidFinish()、onExit()、onExitTransitionDidStart()等更多相关知识的信息可以在本站进行查询。

本文标签: