在我的程序中说,我有这个paint()方法。我的愿望是创建绘制的矩形的图像(使用 for 循环)。我尝试了下面的方法,它确实给了我那些矩形(蓝色),但背景全是黑色。当我在不创建图像的情况下运行程序时,只需在 JFrame 上绘制矩形,背景为白色。我怎样才能解决这个问题。?
public void paint(Graphics g) {
super.paint(g);
BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
g = Image.getGraphics(); <<<----- is this correct?
g.setColor(Color.blue);
for ( ..... ) {
g.fillRect(X , Y, width , height);
....
}
try {
ImageIO.write(image, "jpg", new File("CustomImage.jpg"));
}catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud) 嗨,我的头现在沸腾了3天!我想获得肽的所有DNA编码:肽是氨基酸序列,即氨基酸M和氨基酸Q可以形成肽MQ或QM
DNA编码意味着每个氨基酸都有一个DNA代码(称为密码子)(对于某些代码,有一个以上的代码,即氨基酸T有4个不同的代码/密码子)
以下代码中的最后一个函数不起作用,所以我想要一个让它适合我,请不要查询集成语言(我忘了它的首字母缩略词!)
private string[] CODONS ={
"TTT", "TTC", "TTA", "TTG", "TCT",
"TCC", "TCA", "TCG", "TAT", "TAC", "TGT", "TGC", "TGG", "CTT",
"CTC", "CTA", "CTG", "CCT", "CCC", "CCA", "CCG", "CAT", "CAC",
"CAA", "CAG", "CGT", "CGC", "CGA", "CGG", "ATT", "ATC", "ATA",
"ATG", "ACT", "ACC", "ACA", "ACG", "AAT", "AAC", "AAA", "AAG",
"AGT", "AGC", "AGA", "AGG", "GTT", "GTC", "GTA", "GTG", "GCT",
"GCC", "GCA", "GCG", "GAT", "GAC", "GAA", "GAG", "GGT", "GGC",
"GGA", "GGG", };
private string[] AMINOS_PER_CODON = …Run Code Online (Sandbox Code Playgroud) 我有以下代码,但我没有找到任何方法将用户的数据添加到表中。我想动态地做到这一点。
我已经创建了 WPF 应用程序并添加了数据网格和按钮,当我单击按钮时会看到数据网格上的数据,我应该如何进行?
private void Button_Click(object sender, RoutedEventArgs e)
{
//get user data...
DataTable dt = new DataTable("Users Info");
DataGrid.ItemsSource = dt.DefaultView;
foreach (var user in users)
{
string firstName = user.Firstname;
string lastName = user.Lastname;
}
Run Code Online (Sandbox Code Playgroud)
Xaml 是:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WPFTest01" x:Class="WPFTest01.MainWindow"
Title="WPF_DEMO_Main" Height="350" Width="525">
<Grid x:Name="Grid" Background="#FF1BA1E2">
<DataGrid x:Name="DataGrid" HorizontalAlignment="Left" Margin="65,60,0,0" VerticalAlignment="Top" Height="185" Width="385" SelectionChanged="DataGrid_SelectionChanged_1"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="390,280,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用其中一些代码但没有成功:(
//dt.Columns.Add("First Name", typeof(string));
//dt.Columns.Add("Last Name", typeof(string));
//DataSet ds = new DataSet(); …Run Code Online (Sandbox Code Playgroud) 我有两个ArrayList,每个Array容纳一定大小的块:blockList,eraseList。块是具有两个字段的对象:开始和结束。我需要从另一组块中减去一组块。
我必须遍历好橡皮擦列表和“擦除”块,使其脱离重叠的blockList。因此,我的代码如下所示:
void eraseBlocks (Arrylist<Blocks> blockList, ArrayList<Blocks> eraserList) {
ListIterator<Blocks> it = blockList.listIterator();
for (Blocks eraser: eraserList) {
while (it.hasNext()) {
Blocks block= it.next();
if ((eraser.start <= block.start) && (eraser.end >= block.end))
blockList.remove(block);
else if ((eraser.start <= block.start) && (eraser.end < block.end)){
block.set(start, eraser.end);
else if () {
...
//more code for where the eraser partially erases the beginning, end, or splits the block
//if statements call the .add(), .set(), and remove() methods on the blockList.
...
}
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写检查数组是否已排序的代码,homework说它必须在带有布尔返回的方法中,但是如果我将返回放在for循环中,它会在for循环之前停止for循环只是列表中的前两位数字.无论哪种方式,即使我把循环中的返回值eclipse告诉我方法中没有布尔返回值?我不知道如何让它工作,在网上找不到任何类似的东西请帮忙:)
public static boolean isSorted (double [] list) {
for (int i=1; i<list.length; i++) {
if (list[(int) i-1] > list[(int) i] ) {
System.out.println("Not Sorted");
return false;
}
else {
return true;
}
}
}
Run Code Online (Sandbox Code Playgroud) 每次指定路径时,我都必须添加其他'\'字符.有没有办法我们可以指定路径
$path=@"C:\Users\Documents";//need this is php
Run Code Online (Sandbox Code Playgroud)
代替
$path="C:\\Users\\Documents";
Run Code Online (Sandbox Code Playgroud)
提前感谢您分享输入
注意:不寻找dirname().
我正在寻找一种方法来获取 zip 文件中的文件列表。我创建了一个方法来获取目录中的文件列表,但我也在寻找一种方法来获取 zip 中的文件,而不是只显示 zip 文件。
这是我的方法:
public ArrayList<String> listFiles(File f, String min, String max) {
try {
// parse input strings into date format
Date minDate = sdf.parse(min);
Date maxDate = sdf.parse(max);
//
File[] list = f.listFiles();
for (File file : list) {
double bytes = file.length();
double kilobytes = (bytes / 1024);
if (file.isFile()) {
String fileDateString = sdf.format(file.lastModified());
Date fileDate = sdf.parse(fileDateString);
if (fileDate.after(minDate) && fileDate.before(maxDate)) {
lss.add("'" + file.getAbsolutePath() +
"'" + " Size KB:" …Run Code Online (Sandbox Code Playgroud)