我试图在java中实现一个堆栈(使用列表接口:接口列表).
我想以两种不同的方式实现它:使用组合和继承.
对于继承,到目前为止我有:
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class StackInheritance implements List {
//implement list methods
}
Run Code Online (Sandbox Code Playgroud)
对于作文,我有:
import java.util.List;
public abstract class StackComposition implements List {
// implement some standard methods
}
public class StackViaList extends StackComposition {
// implement methods that have not been implemented in the abstract
// class
}
Run Code Online (Sandbox Code Playgroud)
我很困惑从哪里开始.我之前从未使用过接口,所以我是否应该使用List方法来"模仿"堆栈,例如使用Array或ArrayList?
另外,对于合成,我不明白应该在StackComposition中使用哪些方法以及应该在StackViaList中使用什么方法.在不完全理解接口以及继承和组合之间,我有点迷失.我似乎还不能"得到它"......
任何帮助将不胜感激,谢谢!
我想知道我是否可以就网络Tic Tac Toe游戏的最佳/最有利的设计模式得到你的想法和建议?
我一直在研究以下设计模式:Factory,Abstract Factory,Singleton,Prototype和Builder.
根据您的经验,这将是最好的使用,为什么?
现在,我的Tic Tac Toe游戏是一个线程客户端/服务器游戏,可以通过套接字在互联网上播放.但是,我将以某种方式重构游戏以利用设计模式.
我正在考虑建立一个可用于播放许多不同类型游戏的客户端/服务器架构,例如tic tac toe,connect 5等...
我应该去哪个方向?我希望进入一个真正能给我一些设计模式经验的方向......
谢谢!
是否可以将对象传递给PHP类的构造函数,并将该对象设置为可由类中其余函数使用的全局变量?
例如:
class test {
function __construct($arg1, $arg2, $arg3) {
global $DB, $ode, $sel;
$DB = arg1;
$ode = arg2;
$sel = $arg3;
}
function query(){
$DB->query(...);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试这样做时,我得到一个"对非对象的成员函数调用"错误.反正有没有这样做?否则,我必须直接将对象传递给每个单独的函数.
谢谢!
是否可以提交HTML表单(带有PHP操作)并包含javascript onsubmit="VerifyFields()?
我现在正在尝试这样做,但似乎它将执行PHP操作而不是执行此操作onsubmit.
感谢您所有的帮助.
问题是我把我的VerifyMe()功能放在了<head></head>,而不是<body></body>.
我有以下字符串:
oauth_token=safcanhpyuqu96vfhn4w6p9x&**oauth_token_secret=hVhzHVVMHySB**&application_name=Application_Name&login_url=https%3A%2F%2Fapi-user.netflix.com%2Foauth%2Flogin%3Foauth_token%3Dsafcanhpyuqu96vfhn4w6p9x
Run Code Online (Sandbox Code Playgroud)
我试图解析oauth_token_secret的值.我需要从等号(=)到下一个&符号(&)的所有内容.所以我需要解析:hVhzHVVMHySB
目前,我有以下代码:
Const.OAUTH_TOKEN_SECRET = "oauth_token_secret";
Const.tokenSecret =
content.substring(content.indexOf((Const.OAUTH_TOKEN_SECRET + "="))
+ (Const.OAUTH_TOKEN_SECRET + "=").length(),
content.length());
Run Code Online (Sandbox Code Playgroud)
这将从oauth_token_string的开头开始,但不会在下一个&符号处停止.我不确定如何指定在以下&符号的末尾停止.谁能帮我?
在大多数情况下,我的HTTP请求工作没有问题.但是,他们偶尔会挂起来.
我正在使用的代码设置为如果请求成功(响应代码为200或201),则调用screen.requestSucceeded().如果请求失败,则调用screen.requestFailed().
但是,当请求挂起时,它会在调用上述方法之一之前执行此操作.我的代码有问题吗?我应该使用某种最佳做法来防止任何悬挂吗?
以下是我的代码.我将不胜感激任何帮助.谢谢!
HttpConnection connection = (HttpConnection) Connector.open(url
+ connectionParameters);
connection.setRequestMethod(method);
connection.setRequestProperty("WWW-Authenticate",
"OAuth realm=api.netflix.com");
if (method.equals("POST") && postData != null) {
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", Integer
.toString(postData.length));
OutputStream requestOutput = connection.openOutputStream();
requestOutput.write(postData);
requestOutput.close();
}
int responseCode = connection.getResponseCode();
System.out.println("RESPONSE CODE: " + responseCode);
if (connection instanceof HttpsConnection) {
HttpsConnection secureConnection = (HttpsConnection) connection;
String issuer = secureConnection.getSecurityInfo()
.getServerCertificate().getIssuer();
UiApplication.getUiApplication().invokeLater(
new DialogRunner(
"Secure Connection! Certificate issued by: "
+ issuer));
}
if (responseCode != 200 && responseCode != 201) {
screen.requestFailed("Unexpected …Run Code Online (Sandbox Code Playgroud) 我想知道将00:00:00格式的时间字符串转换为整数或长整数的最佳方法是什么?我的最终目标是能够将一堆字符串时间转换为整数/长整数,将它们添加到数组中,并在数组中查找最近的时间...
我很感激任何帮助,谢谢!
好的,根据答案,我决定继续直接比较字符串.但是,我遇到了一些麻烦.可能有一个以上的"最近"时间,即两次相等的时间.如果是这种情况,我想将这两个时间的索引添加到ArrayList.这是我目前的代码:
days[0] = "15:00:00";
days[1] = "17:00:00";
days[2] = "18:00:00";
days[3] = "19:00:00";
days[4] = "19:00:00";
days[5] = "15:00:00";
days[6] = "13:00:00";
ArrayList<Integer> indexes = new ArrayList<Integer>();
String curMax = days[0];
for (int x = 1; x < days.length1; x++) {
if (days[x].compareTo(curMax) > 0) {
curMax = days[x];
indexes.add(x);
System.out.println("INDEX OF THE LARGEST VALUE: " + x);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这是在ArrayList中添加索引1,2和3 ...
谁能帮我?
以下两个编码字符串有什么区别?
%D0%9E%D0%BA%D0%B6%D1%8D%D0%B7
Run Code Online (Sandbox Code Playgroud)
和
%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B
Run Code Online (Sandbox Code Playgroud)
我正在尝试URL将俄语文本"Привет"编码到上面的第二个编码字符串中(W3Schools编码器正确执行),但我使用的URL编码器一直给我上面的第一个编码字符串.我正在使用W3联盟的URLUTF8Encoder.java.当我在需要J2ME的移动平台上工作时,我必须使用这个.
谢谢!
我的 TableLayout 遇到问题。它由两列和多行组成。当第二列的 TextView 包含较长宽度的文本时,它将将该列(下面的行)中的 TextView 推离屏幕(向右)。相反,我希望它将文本保留在左侧,并在末尾用省略号限制文本。谁能看出我的 XML 有什么问题吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#4096cc" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/roundedshape"
android:layout_margin="5dp"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Server Name"
android:textStyle="bold"
android:padding="10dip" />
<TextView
android:id="@+id/txtServerName"
android:text=""
android:gravity="right"
android:ellipsize="end"
android:padding="10dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:layout_column="1"
android:text="Status"
android:textStyle="bold"
android:padding="10dip" />
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="10dip"
android:src="@drawable/icon" />
</TableRow>
.
.
.
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个LinearLayout,其中包含基本上模仿3x2网格的子布局.每个子布局在屏幕上占据相同的空间(宽度).现在,我希望两排子布局在高度上伸展,这样每个子布局占据屏幕的50%.我已经尝试过使用权重,但是我不知道如何修改现有的布局代码而不会弄乱用于宽度的现有权重.任何人都可以给我一些帮助吗?谢谢!这是我的布局代码:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_marginBottom="2dip"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginRight="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage1"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage1"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginLeft="1dip"
android:layout_marginRight="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage2"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage2"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="50"
android:padding="10dip"
android:layout_marginLeft="1dip"
android:background="@drawable/detail_row"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/menuImage3"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textImage3"
android:layout_column="1"
android:layout_gravity="center_horizontal|center_vertical"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout> …Run Code Online (Sandbox Code Playgroud) java ×6
string ×3
android ×2
php ×2
xml ×2
blackberry ×1
composition ×1
encoding ×1
forms ×1
hang ×1
html ×1
http ×1
inheritance ×1
java-me ×1
javascript ×1
layout ×1
list ×1
request ×1
scope ×1
stack ×1
substring ×1
syntax ×1
tablelayout ×1
time ×1
utf-8 ×1